I am trying to create a bash script to ssh into a session and run a command then exit out of the session. currently this is what i have so far:
#!/usr/bin/expect -f
spawn ssh root@sc
expect "assword:"
send "password\r"
expect "#"
send "cd /data2/someDirectory\r"------> don't see this command being executed
and the output
[user@San ddb]$ test1
spawn ssh root@sc
root@sc's password:
SC02 RH 7.3 (0000009B 02.11.0.1)
[root@sc /]# [user@san1 ddb]$
[user@san1 ddb]$
So my question is why isn't the directory being set to myDirectory and it just exits out of the session?
Your expect
script is doing what you are intending but is quitting once the job is send
is done.
set some "expectation" like expect "$"
at the end of the script and try.
#!/usr/bin/expect -f
spawn ssh [email protected]
expect "assword:"
send "pass\r"
expect "#"
send "\r"
send "pwd\r"
send "\r"
send "cd /tmp\r"
send "touch dummy\r"
expect "$"
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments