Find the answer to your Linux question:
Results 1 to 2 of 2
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Help with 'expect'

    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 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

    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
     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.

  2. #2
    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
    arp -a
    here's a real quick expect script example that will use sftp to push a file to a remote machine:

    set USER user
    set PASSWORD testpass
    set IPADDR
    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
    it does not do any error checking, etc., so you should figure out how to do that. also, you can configure it to take the password (any any other args really) from the command line, if that makes more sense in your application.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts