如何在Python中通过ssh调用.ksh文件作为Unix命令的一部分

2024-09-29 17:14:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我想实现以下目标:

给定的文件包含一个作业列表,我需要使用sshapi在远程服务器中逐个执行并存储结果。在

当我尝试使用putty在远程服务器上直接调用以下命令时,它将成功执行,但当我尝试通过pythonsh编程执行它时,它会显示cant findautosys.ksh公司. 在

autosys.ksh autorep -J JOB_NAME

有什么想法吗?请帮忙。提前谢谢。在


Tags: 文件命令服务器目标列表远程编程作业
2条回答

Fabric是个不错的选择。在主页上

Fabric is a Python (2.5 or higher) library and command-line tool for streamlining the use of SSH for application deployment or systems administration tasks.

一个简单的例子

>>> from fabric.api import run, env, cd, settings, hide, show
>>> env.host_string='xxx.xxx.com'
>>> env.user='user'
>>> env.password='password'
>>> run('ls -lart')

在阅读了您对第一个答案的评论之后,您可能需要创建一个bash脚本,其中bash path作为解释器行,然后是autosys命令。在

这将创建一个bashshell并从shell中的脚本运行命令。在

如果用户在autosys环境中再次运行autosys命令,最好在autosys命令之前使用autosys命令。在

相关问题 更多 >

    热门问题