[英]redirection of a wlst command to a file in python script
There is a command with arguments like this in a python script python脚本中有一个带有这样的参数的命令
ThreadDump('true', 'location', servername) ThreadDump('true','location',服务器名)
the above command is a wlst command that takes a thread dump for that server and it redirects the dump file to that location and that file in that location. 上面的命令是一个wlst命令,该命令执行该服务器的线程转储,并将转储文件重定向到该位置和该位置的文件。
But the ThreadDump() is in a for loop from 1 to 6, so the thread dump has to happen 5 times, and each time the dump information has to be appended to the file. 但是ThreadDump()处于1到6的for循环中,因此线程转储必须进行5次,并且每次转储信息都必须附加到文件中。
Tried the entire output of the python file to a another file using >& option, but the problem with this is there is a CRON job that is running and the original dump information is getting rewritten with the new information. 使用>&选项将python文件的整个输出尝试到另一个文件,但是问题是正在运行一个CRON作业,并且原始转储信息被新信息重写。
so, just need to redirect and append that above command 因此,只需要重定向并附加上面的命令
ThreadDump('true', 'location', 'servername') to a file >> /dir/newdir/file ThreadDump('true','location','servername')到文件>> / dir / newdir / file
or ThreadDump('true', 'location', 'servername') to a file >& /dir/newdir/file 或ThreadDump('true','location','servername')到文件>&/ dir / newdir / file
如果您可以使用文件中的threaddump从脚本重定向输出,并且唯一的问题是运行此脚本的cron作业,请尝试编辑crontab以在其中添加>>(2>&1用于将stderr预测为stdout):
*/15 * * * * /path/to/shell/script.sh >> /www/logs/script.log 2>&1
It would be easier to understand with a sample of the original code, but I think that maybe you can do something like 使用原始代码示例会更容易理解,但是我认为也许您可以执行类似的操作
import os
import fileinput
for i, whatever in enumerate(list_of_threads_or_something):
ThreadDump('true', 'location' + str(i), servername)
# do whatever else you need to do
locations = ['location'+str(i) for i in range(6)]
with fileinput.input(locations) as f, open('location', 'w') as fout:
for line in f:
fout.write(line)
for loc in locations:
os.remove(loc)
change 'location'
as needed 根据需要更改
'location'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.