To write a shell script that will remote login to machineB from machineA

B

Basudeba Mandal

Guest
I wanna write a shell script which will do remote login to a machine,
If I use ssh command to do that, It asks something like 'do you wanna continue (yes/no)' and then remote machine's password, so
there we need to input yes and next input is remote machine's password. So my doubt is,
how to give those two input(yes and remote machine's password) to the system? Can I use the below command

echo 'yes abcd' | ssh --stdin [email protected]

where 'abcd' is the password of 'user25'(user25 is an user on remote machine 192.168.1.1')

or I need to give input from file????
 


R

ryanvade

Guest
Code:
#!/usr/bin/expect -f
# ./sshlogin.exp uptime
# set Variables
set user username
set password yourpassword
set ipaddr serveripaddress
set arg1 [lrange $argv 0 0]
set timeout -1
# now connect to remote UNIX box (ipaddr) with given script to execute
spawn ssh [email protected]$ipaddr $arg1
match_max 100000 # Look for passwod prompt
expect "*?assword:*"
# Send password aka $password
send -- "$password\r"
# send blank line (\r) to make sure we get back to gui
send -- "\r"
expect eof
 
B

Basudeba Mandal

Guest
Thanks for your help....
Actually I am new to shell script. And a just beginner to expect script. So some doubts are coming to my mind.

set arg1 [lrange $argv 0 0]
what is this [lrange $argv 0 0]?
why this setting is needed?

spawn ssh [email protected]$ipaddr $arg1
why $arg1, can we do without that?

match_max 100000
whats this match-max?what does it do?
 
B

birdboyee

Guest
Ryan, can you help me with the following? We use a SecureCRT .vbs script to automate logging into multiple boxes, however, I'd like to have something run in Linux vs. our emulator. Below is my objective:

Our current .vbs script will look at an IP list .txt file on our PC, then login to each IP within the .txt, and execute the following:

Code:
ssh [email protected][IP Address]
su - root  # We get prompted for PW.
su - secadmin2  # We do not get prompted for PW.
cd .ssh
cp authorized_keys authorized_keys_bkup
cat /app2/.ssh/Vkey >> authorized_keys
exit
exit
cd .ssh
cp Vkey Vkey.orig
cat Vkey >> authorized_keys
rm /app2/.ssh/Vkey
exit
Again, the script must prompt for root password (only once since all root PW's will be the same), and loop commands above for all IP's found on file. Can anyone help with this? Your assistance and cooperation is GREATLY appreciated!
 



Members online



Top