【问题标题】:How to include and run all python scrips in single wrapper script如何在单个包装脚本中包含和运行所有 python 脚本
【发布时间】:2020-12-01 17:15:19
【问题描述】:

我有大约 12 个 python 脚本,我分别执行它们 现在我想将这 12 个脚本包含在单个 shell 包装器中,并希望运行这个可以一次执行所有 12 个的包装器。 我尝试了以下简单的 shell 但无法执行它

#!/bin/bash
/home/<user>/serverlist.py
/home/<user>/cluster.py
/home/<user>/listApps.py

`
[root@bin]# ./wsadmin.sh -lang jython -f /home/Devop/wrapper.py
WASX7209I: Connected to process "server1" on node localhostNode02 using SOAP connector;  The type of process is: UnManagedProcess
WASX7017E: Exception received while running file "/home/Devop/wrapper.py"; exception information: com.ibm.bsf.BSFException: exception from Jython:
Traceback (innermost last):
  (no code object) at line 0
  File "<string>", line 3
    sh "./home/Devop/listApps.py" 
       ^
SyntaxError: invalid syntax`
I  am getting this syntax error

【问题讨论】:

  • “无法”怎么办?如果路径正确,这个脚本应该可以工作。
  • stackoverflow.com/questions/41079143/… 的可能重复项(简单提示:将 bash 替换为 python3 或任何你的 Python 解释器,或者如果脚本具有有效的 shebang 和执行权限,则省略它)。
  • bash 是#! 中正确的解释器,但您需要每次都放入整个 wsadmin 命令,然后在 bash 中执行包装器,而不是 wsadmin。所以./wsadmin.sh -lang jython -f /home/&lt;user&gt;/serverlist.py等等。您在 shell 中以 ./wrapper.sh 的形式运行该脚本。否则,您必须在单个 wsadmin 脚本中使用 execfile 来执行其他脚本,请参阅 github.com/WASdev/sample.daytrader7/blob/…

标签: python shell unix websphere


【解决方案1】:
#!/bin/bash
python3 /home/<user>/serverlist.py #or just python
python3 /home/<user>/cluster.py
python3 /home/<user>/listApps.py

【讨论】:

  • 请注意,如果这些脚本是 WebSphere wsadmin 脚本,您必须使用 wsadmin.sh 和 -f 参数运行它们,因为它们需要活动 WAS wsadmin 会话的上下文才能实际运行。跨度>
猜你喜欢
  • 1970-01-01
  • 2023-01-08
  • 1970-01-01
  • 2016-06-24
  • 2023-03-31
  • 1970-01-01
  • 2010-11-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多