Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ssh to server and change directories

Status
Not open for further replies.

neonep

Programmer
Jun 26, 2003
34
Hi everyone,

For various debugging tasks, I regularly need to log into 3 different servers and look at 2 different log files on each. It would be awesome to have a script that would open gnome-terminal with multiple tabs ssh'ed to different servers and cd each tab to a directory of my choosing. Does anyone have a script that can do this? I have public/private key authentication set up, so I don't have to enter any passwords.

-------

I found the following script 1 and came up with script 2. Both look promising but they have their flaws.

1.

konsole --script -e ssh user@server1 &
sleep 1
KONSOLE=`dcop | grep konsole | tail -n 1`
SESSION=`dcop $KONSOLE konsole newSession`
sleep 1
dcop $KONSOLE $SESSION sendSession "user@server2"
sleep 1
dcop $KONSOLE $SESSION sendSession "cd /some/folder"

I really don't understand this script although it logs into two servers and changes directories for one. How can I make it do the same for one more server?

2.

gnome-terminal --tab-with-profile=default -t server:log -e "ssh user@server1" --tab-with-profile=default -t server:log -e "ssh user@server2"

This logs into different servers but I don't know how to make it change directories.

-------------

Any help will be greatly appreciated.

Thanks.
 
I like TCL/Expect for this kind of thing. It's meant for writing interactive scripts. I use it for automated config changes on my Cisco switches.

The commands are simple:

call "telnet 192.168.0.1"
wait "user:"
send "foo"
wait "password:"
send "foobar"
wait "cisco >"
send "set port blah blah blah"
wait "cisco >"

This is psuedo code but it's close to the actual syntax

shauber
 
why don't you use the syslog mechanism and let them all log to a central syslog server.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top