Run a perl script on remote machine from local machine using Telnet or SSH with Perl

偶尔善良 提交于 2020-01-23 12:26:02

问题


I want to run a Perl script in a remote machine using telnet or ssh. The script is on my local host.how can do this. Can anyone please help me on this?


回答1:


If you for some reason don't want to copy the script to the remote host and then run it, you can send the script to the Perl interpreter over stdin. If perl doesn't get either a script name of a script on the command line it tries to read the script on stdin. So this would work:

ssh user@remote perl < my_script.pl

Of course this requires that all necessary modules are already installed on the remote host. If you script only have pure perl dependencies you can work around this restriction by using App::FatPacker to make your script (more) self contained.

But if this is an recurring task I would recommend getting the script deployed correctly to your remote host.




回答2:


scp your script to remote machine.
ssh user@remote 'perl /path/to/remote/script.pl'



回答3:


Using HERE document across SSH might also do the trick you are after. You can run at least a BASH script without first separately copying it to remote. I have not verified anything else than BASH but no reason to doubt either. Please see:

ssh + here document + interactive mode



来源:https://stackoverflow.com/questions/12616671/run-a-perl-script-on-remote-machine-from-local-machine-using-telnet-or-ssh-with

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!