Filename: login
#!/usr/bin/expect
eval spawn ssh username@servername
expect "assword:"
send "server_password\r"
interact
# to run the script
# ./login
In this below script you can pass arguments to the shell script
eval spawn ssh username@servername
expect "assword:"
send "server_password\r"
interact
# to run the script
# ./login
Filename: login
#!/usr/bin/expect
set num [lindex $argv 0];
eval spawn ssh username@servername-$num
expect "assword:"
send "server_password\r"
interact
# make sure to give executable permission to script.
chmod +x login
# to run the script and login to server-01.
./login 01
set num [lindex $argv 0];
eval spawn ssh username@servername-$num
expect "assword:"
send "server_password\r"
interact
# make sure to give executable permission to script.
chmod +x login
# to run the script and login to server-01.
./login 01
Now add the script path to your .bashrc file as alias, so that you can access this script from any path.
# vi ~/.bashrc
alias login='/path/to/script/file/login'
alias login='/path/to/script/file/login'
After updating the .bashrc file, you will have to source.
source ~/.bashrc
Now call the script from anywhere in your shell.
login 01
Enjoy!!!
No comments:
Post a Comment