[英]Is there any way to run a python script on remote machine without sending it?
I can run a shell script on remote machine with ssh. 我可以使用ssh在远程机器上运行shell脚本。 For example:
例如:
ssh -l foo 192.168.0.1 "`cat my_script.sh`"
Now I want to run a python script without sending .py file. 现在我想运行一个python脚本而不发送.py文件。 Is there any way?
有什么办法吗?
This will put the contents of my_script.py on your computer into an echo command that is performed on the remote computer and passed into python. 这会将my_script.py的内容放在您的计算机上,并在远程计算机上执行并传递给python的echo命令。
ssh -l foo 192.168.0.1 "echo '`cat my_script.py`' | python"
If you want to add command line args it should be as simple as putting them after the python command like so: 如果你想添加命令行参数,它应该像在python命令之后那样简单地添加它们:
ssh -l foo 192.168.0.1 "echo '`cat my_script.py`' | python -testSwitch -arg 0"
Make sure that the command line args are inside the double quotes of the command you are sending to the remote host. 确保命令行参数位于要发送到远程主机的命令的双引号内。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.