Ssh, run a command on login, and then Stay Logged In?

Posted by jonathan on Server Fault See other posts from Server Fault or by jonathan
Published on 2009-10-29T18:05:59Z Indexed on 2010/05/28 21:54 UTC
Read the original article Hit count: 503

Filed under:
|
|
|

I tried this with expect, but it didn't work: it closed the connection at the end.

Can we run a script via ssh which will log into remote machines, run a command, and not disconnect?

So ssh in a machine, cd to such and such a directory, and then run a command, and stay logged in.

-Jonathan

(expect I used)

#!/usr/bin/expect -f
set password [lrange $argv 0 0]
spawn ssh root@marlboro "cd /tmp; ls -altr | tail"
expect "?assword:*"
send -- "$password\r"
send -- "\r"
interact

© Server Fault or respective owner

Related posts about linux

Related posts about ssh