Reputation: 89
There is a command with arguments like this in a python script
ThreadDump('true', 'location', servername)
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.
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.
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.
so, just need to redirect and append that above command
ThreadDump('true', 'location', 'servername') to a file >> /dir/newdir/file
or ThreadDump('true', 'location', 'servername') to a file >& /dir/newdir/file
Upvotes: 1
Views: 1802
Reputation: 1860
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
Upvotes: 0
Reputation: 22571
If you can redirect output from script with threaddump in file and only problem is with cron job that run this script, try to edit crontab to add >> in it (2>&1 used to redict stderr to stdout):
*/15 * * * * /path/to/shell/script.sh >> /www/logs/script.log 2>&1
Upvotes: 1