Results 1 to 2 of 2
hi guys I am in need for some 'expect' scripting help I have the following bash script and need to make this automated using the same password everytime (since i ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 07-09-2012 #1
- Join Date
- Jul 2012
Help with 'expect'
I have the following bash script and need to make this automated using the same password everytime (since i am configuring different deviced everytime, I can not use SSH Key for this)
Can anyone tell me how to integrate the 'expect' usages into this script so that MySecrectPass will be used to log into the ssh and transfer the files and get mac address:
please find the bits I need automated below
login="user(at)192.168.1.99" ssh_args="-o StrictHostKeyChecking=no" #Get the mac address mac=$(echo "ip -o link show dev eth0 | sed 's/.*link\/ether \([0-9:a-f]*\).*/\1/g'" | ssh $ssh_args $login) if [[ $mac == "" ]]; then exit fi echo "CPE mac address == $mac" scp $ssh_args -r system.cfg $login:/tmp/ scp $ssh_args cp ../XM* $login:/tmp/fw.bin
Last edited by geotor; 07-09-2012 at 12:57 AM.
- 07-09-2012 #2
- Join Date
- May 2011
if you have the ip address, you can get the MAC address via the arp table, instead of running a remote login and running a command to get it.
first ping the remote machine, then grab it via the arp command, e.g.:
ping -c3 192.168.1.99 arp -a 192.168.1.99
#!/usr/bin/expect set USER user set PASSWORD testpass set IPADDR 192.168.1.99 set FILE testfile set RDIR /tmp # make sftp connection spawn -noecho sftp $USER@$IPADDR expect "password:" send "$PASSWORD\n"; expect "sftp>" send "cd $RDIR\n"; expect "sftp>" send "put '$FILE'\n"; expect "sftp>" send "quit\n"; exit 0