ubuntu远程运行python

Python025

ubuntu远程运行python,第1张

要在Ubuntu上远程运行Python脚本,首先需要在Ubuntu上安装SSH服务器,然后通过SSH客户端连接到服务器,最后通过shell指令运行Python脚本。另外,也可以使用可视化的SSH工具来管理Ubuntu服务器上的文件,实现远程运行Python。

首先python基础你得会:

最简单套路:web用flask,linux交互用subprocessor模块

说白了就三点:python基础、flask框架、subprocessor模块

相比于 Shell,Python 提供了更好的流程控制,因此,前一段时间我尝试使用 Python 完成了 sync-deploy 命令集的重写(见 另一篇文章 )。后续新特性的添加都只将在 loon 项目《 https://github.com/ShixiangWang/loon 》上,sync-deploy 只负责维护异常的修复。

值得一提的是,loon 的使用需要 Python 3的环境以及几个依赖包,所以 sync-deploy 可能更加轻量。

loon is a Python toolkit for operating remote host based on SSH. Idea for developing loon comes from sync-deploy , which is limited by its pure bash code. Therefore, I use Python to implement it and more features will be added to it in the future.

Install from pypi:

Install from GitHub:

To access remote host without typing password, you have to generate ssh key with ssh-keygen command if it is not available.

Follow the commands, for simplicity, just type ENTER to proceed.

Copy your key to remote server, replace user with your username and host with your remote host ip address.

This will upload scripts to remote host firstly, then run them.

You can include data directory using --data flag, specify program like bash or python using --prog flag and set remote directory using --dir flag.

Use them like cp command. At default, use scp command to do the job, set --rsync to use rsync command ( --rsync is disabled in Windows).

By providing a structed file (CSV, TSV etc) and a sample command with placeholders {index} refer to column index (0 based) of file, batch command can be used to execute a batch of commands. Users can set thread number by -T flag and use --dry flag to dry run the code.

More details please see -h option of the commands above.