简体   繁体   中英

Run a perl script inside another script using ssh

I have a perl script where I need to connect to another machine using ssh and there run another perl script. I tried using this line:

system("ssh $admin_server 'perl /Perl/scripts/capture_server_restarts_gse.pl $month $date'");

But everytime the script gets to that line, I get the prompt for the remote machine and the script doesn't run.

How can I fix this so the script runs automatically on the other machine without showing the prompt.

Note: I don't need the password and user to connect to the remote machine we already solved that.

Why not copy your public key onto the other machine ? That way you'll be pre-authorised.

Here are the instructions on how to do this using ssh-keygen

Otherwise you have to feed ssh with your password, and that's tricky since ssh normally takes input from a tty and you have to configure your script with the password.

The SSH server may be configured to run always some custom shell instead of the command passed from the client.

Try just running some simple command from the command line, ie:

  ssh server ls

A less likely possibility is that the perl variables interpolated into the system argument could contain some shell metacharacters requiring better escaping. For instance, a semicolon inside $admin_server.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM