-----Original Message----- From: Simon [mailto:simon.parkes@btconnect.com] Sent: 28 August 2002 07:25 To: main@lists.alug.org.uk Subject: [Alug] Remote command execution..
Hi all, Is it possible to fire up ssh and run a remote command in a perl script, somthing like :
system("ssh <user>@<host>:/<command>");
the command would be system("ssh <user>@<host> <command>"); (or at least the ssh part is like that as I've not checked the perl system() command)
Would the above run the command then quit or stay logged in ?
It should return when the remote command returns and it's return code will be that of the remote command. Remember that for it to work without asking for a password you need to have a key-pair set up without a password on it or use ssh-agent to remember the password for the key.
Basicaly I need to run a script on a local machine and dependant upon results, run a script on a remote machine, then continue back with the script on the local machine.
Hope it makes sense..
TIA Simon
JD
_____________________________________________________________________ This message has been checked for all known viruses by the MessageLabs Virus Scanning Service
Jonathan Dye jonathan.dye@automationpartnership.com writes:
Is it possible to fire up ssh and run a remote command in a perl script, somthing like :
system("ssh <user>@<host>:/<command>");
the command would be system("ssh <user>@<host> <command>"); (or at least the ssh part is like that as I've not checked the perl system() command)
Remember to get the quoting right if you do it like that. An easier approach would be:
system("ssh", "<user>@<host>", "<command>");
...which the requirement for one level of quoting.
Would the above run the command then quit or stay logged in ?
It should return when the remote command returns and it's return code will be that of the remote command.
Not quite, it won't:
sfere$ ssh sfere exit 3 ; echo $? 3 sfere$ sh -c 'kill -KILL $$' ; echo $? Killed 137 sfere$ ssh sfere 'kill -KILL $$' ; echo $? 255 sfere$ ssh -V OpenSSH_3.4p1 Debian 1:3.4p1-1, SSH protocols 1.5/2.0, OpenSSL 0x0090603f