running command with expect

17,183

You can simply add statements to your script:

#!/usr/bin/expect
set login "root"
set addr "10.3.2.0"
set pw "root"

spawn ssh -t $login@$addr
expect "$login@$addr\'s password:"
send "$pw\r"
expect "~" ; # put here string from your server prompt
send "mkdir some_dir\r"
interact
Share:
17,183
Uvais Ibrahim
Author by

Uvais Ibrahim

Enthusiastic in Linux/Unix. Trying to learn the soul of Linux. :)

Updated on June 04, 2022

Comments

  • Uvais Ibrahim
    Uvais Ibrahim almost 2 years


    I have created a shell script which will automate login to a remote machine.
    But I need to automate the execution of commands or shell scripts also along with this script.
    What modification do I need to do with shell script for creating a directory(for example!) in the remote machine ?

    #!/usr/bin/expect
    set login "root"
    set addr "10.3.2.0"
    set pw "root"
    
    spawn ssh -t $login@$addr
    expect "$login@$addr's password:"
    send "$pw\r"
    interact
    

    Thanks in advance.