![]() ![]() Last login: Sun Jun 9 19:54:17 2013 from # su - # ls -ltr Here is the output when I run the above expect script with correct parameters. The last expect command just shows that we can send commands also once we are logged into the server.The only thing to check is that the regular expression for the expect command should matches, so that it will send the corresponding command or password. The other expect regular expressions varies across the servers, for my server it ends with “#” but for some other servers it might end with “$”, so you may need to edit it accordingly.The first Yes/No choice is added to make sure that it doesn’t fail if remote server key is not already imported. ![]() Notice the expect command followed by the regular expression and then what should be send as a response.Expect script default timeout is 10 seconds, so I have set the timeout to 60 seconds to avoid any timeout issues if the login prompt takes time to come.Notice the first line that specifies that expect script will be used as interpreter.sshsudologin.expect #!/usr/bin/expectĮxpect "*?assword" Here is the script I created for automatically login to the SSH server and then login with super user and then run a simple command. Expect ScriptĮxpect Script is very easy to learn and as the name suggests it works by parsing the output of the command and when it matches the specified regular expression, it processes the specified instruction. Then I come to know about expect script that allows to automate the interaction with programs that opens a terminal for input. CYGWIN SSH SHELL HOW TOWhen I first started working on this, I got stuck as how to enter the SSH password because normal unix shells don’t have any way to send the password when it gets prompted for login. ![]() So I thought of writing a script that will automatically login me to the server. It’s kind of messy when the number of servers are huge. So I need to remember a lot of SSH users, their passwords and then SU users and passwords. I have to deal with a lot of unix servers in my daily life, whether it’s at work or it’s my hosting server. Expect script is a great linux/unix utility. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |