I would like to make a batch (.bat file) that automatically opens several
Putty sessions.
No problem for the moment. But moreover I want to execute some specific
commands for each session.
I tried to use the -m option of the Putty command line to execute the
commands set in a specified file but it seems that the Putty session is
closed after the command are executed.
Is there a way to do that ?
Thank in advance.
PS : the idea is to open a Putty session for each host where I have to check
some logs, to go to the proper log directory and make a tail -f on a log
file for instance.
PiRanha
After the commands finish running, why wouldn't the window close?
Perhaps you want to finish the commands with a shell that remains
running?
> PS : the idea is to open a Putty session for each host where I have to check
> some logs, to go to the proper log directory and make a tail -f on a log
> file for instance.
Maybe instead of running a command (like tail), you want to run a shell
and have it run the command, or just invoke a new shell at the end.
--
Darren Dunham ddu...@taos.com
Senior Technical Consultant TAOS http://www.taos.com/
Got some Dr Pepper? San Francisco, CA bay area
< This line left intentionally blank to confuse you. >
Yes, I want to open a shell with some commands automatically launched at the
shell opening.
In fact the main idea is the following : assuming I have an applicative
component hosted by 4 machines (A, B, C, D). If I have to analyse an issue
concerning that component I'd like to be able to get in one click (launching
my .bat file) one Putty session (shell) opened on each of the 4 machines,
with current directories set to the directory containing the log of the
component (using a "cd" command) and, why not, a "tail -f" on the log file.
It a question of efficiency : I'd like to avoid me wasting time to manually
open the 4 sessions, go into the right directories, view the log files.
PiRanha
Yes, I want to open a shell with some commands automatically launched at the
So this isn't really a putty question, it's trying to figure out how to
get a shell to do that.
I tried some simple tacks of executing 'tail ; $SHELL', but I never got
the shell to invoke (although $SHELL ; tail ; $SHELL seemed to work...).
I don't have a simple answer. Maybe a shell script on the box that did
the tail, then ran a shell. Run that script from putty...
May be it is not possible with the current version of Putty :(
However, if it is the case, I think it would be a nice feature.
PiRanha
That should work just fine, but as always, YMMV.
If you want a batch file to kick off multiple sessions then you would
basically create your file with the following lines:
----
putty -l <username_with_rights_to_log> -load "<sessionname0>"
putty -l <username_with_rights_to_log> -load "<sessionname1>"
putty -l <username_with_rights_to_log> -load "<sessionname2>"
etc...
> That should work just fine, but as always, YMMV.
And after the tail exits you get a shell prompt in the window? That's
what the OP wanted and what I couldn't recreate easily.
Getting the tail to run by itself (with putty exiting after the tail
does) is trivial.
Indeed, by doing this, the "tail -f" is well done on my log file but as soon
as I make CTRL-C to get the prompt back the window is closed. I'd like to
keep the session opened to be able to manually type other commands.
PiRanha
What I do is have a script or alias on each of my maintained hosts, I
login to those with the -X option or have it enabled in the PuTTY
session and execute the local command which displays an xterm back
to my PC with my logfiles.
Command to tunnel through SSH
xterm -geom 132x34 -title root@<host> -name root@<host> -e tailnet &
Command to run direct to local PC:
/usr/bin/xterm -display your.pc.local:0.0 -geom 132x34 -title
root@<host> -name root@<host> -e tailnet &
(i usually prepend nohup to the second so I can close out the session
and have the xterm still running)
---
tailnet
---
#!/bin/sh
cd /var/log
/usr/bin/tail -f maillog mysqld.log radius/radius.log &
cd /var/log/httpd
/usr/bin/tail -f site1.com-access_log site1.com-error_log &
exit
---
create a script on the local machine and make it user-executable
---Test---
#!/bin/sh
/usr/bin/tail -f /var/log/messages /var/log/syslog &
/bin/bash
/usr/bin/killall tail
...
---
have PuTTY Execute the script when connecting the same way we did the
tail previously (just put the /path/to/script in the remote command
field). This will execute the tail, background it and spawn a shell.
The last line, which will execute when you exit the shell, is a very
crude cleanup which would be better done with some logic but you can
extrapolate as needed.
hope one of those two solutions helps....