Reputation: 97
I'm having some trouble with expect.
I'm trying to ssh onto another machine and then create a directory on that machine.
Right now this is what my code looks like:
spawn ssh username@ipAddress
expect "password"
send "password"
file mkdir directoryName
That code is giving me a "permission denied".
When I try replacing
file mkdir directoryName
with
send "mkdir directoryName"
There's no error, but it doesn't make a file. Thanks.
Upvotes: 0
Views: 864
Reputation: 337
This might help you :-
#!/usr/bin/expect
set timeout -1
spawn -noecho bash -c "ssh username@serveraddress 'cd /user/bill/work;<your=command>'"
expect {
-re "assword:"{
send "mypassword/r"
}eof{
wait
}
You must send the command inside ssh
as it will run on remote machine.
Explanation for above script :-
set timeout -1
will set this loop in infinite (but it will exit once spawn
process is finished.
-re
will match regex for assword:
eof
will wait until spawn
is finish.
Upvotes: 1
Reputation: 16438
After sending mkdir
command, wait for eof
to happen.
send "mkdir directoryName\r"
expect eof
Upvotes: 0