I try to execute the following simplified batch job on my linux machine:
root@kali:~/Test_plots# ls
batch_job.txt plot.py
root@kali:~/Test_plots# more plot.py
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0,4)
y = np.sin(x)
plt.plot(x,y)
plt.savefig("test.png")
print "done"
root@kali:~/Test_plots# more batch_job.txt
python plot.py | tee output.txt
root@kali:~/Test_plots# batch < batch_job.txt
warning: commands will be executed using /bin/sh
job 30 at Sat Jan 13 22:35:00 2018
root@kali:~/Test_plots# atq
30 Sat Jan 13 22:35:00 2018 = root
root@kali:~/Test_plots# atq
root@kali:~/Test_plots# ls
batch_job.txt output.txt plot.py
root@kali:~/Test_plots# more output.txt
root@kali:~/Test_plots#
The job should execute plot.py
and save the terminal output to output.txt
. The job seems to fail because the output.txt
is empty.
If I execute the job manually, it succeeds:
root@kali:~/Test_plots# more batch_job.txt
python plot.py | tee output.txt
root@kali:~/Test_plots# which sh
/bin/sh
root@kali:~/Test_plots# sh
# python plot.py | tee output.txt
Fontconfig warning: ignoring UTF-8: not a valid region tag
done
# exit
root@kali:~/Test_plots# ls
batch_job.txt output.txt plot.py test.png
root@kali:~/Test_plots# more output.txt
done
The plot and the output.txt
was created correctly.
Is there any logging where I could check why the batch job failed?
EDIT
If I comment out the plt
-lines in the script, the batch job finishes correctly.
root@kali:~/Test_plots# ls
batch_job.txt plot.py
root@kali:~/Test_plots# more plot.py
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0,4)
y = np.sin(x)
#plt.plot(x,y)
#plt.savefig("test.png")
print "done"
root@kali:~/Test_plots# batch < batch_job.txt
warning: commands will be executed using /bin/sh
job 34 at Sun Jan 14 00:02:00 2018
root@kali:~/Test_plots# atq
root@kali:~/Test_plots# ls
batch_job.txt output.txt plot.py
root@kali:~/Test_plots# more output.txt
done
root@kali:~/Test_plots#
EDIT2
According to the comment of @match, I changed the content of the file batch_job.txt
to python plot.py 2>&1 | tee output.txt
. Now I obtain the following error:
Fontconfig warning: ignoring UTF-8: not a valid region tag
Traceback (most recent call last):
File "plot.py", line 5, in <module>
plt.plot(x,y)
File "/usr/lib/python2.7/dist-packages/matplotlib/pyplot.py", line 3307, in plot
ax = gca()
File "/usr/lib/python2.7/dist-packages/matplotlib/pyplot.py", line 950, in gca
return gcf().gca(**kwargs)
File "/usr/lib/python2.7/dist-packages/matplotlib/pyplot.py", line 586, in gcf
return figure()
File "/usr/lib/python2.7/dist-packages/matplotlib/pyplot.py", line 535, in figure
**kwargs)
File "/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.py", line 81, in new_figure_manager
return new_figure_manager_given_figure(num, figure)
File "/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.py", line 89, in new_figure_manager_given_fig
ure
window = Tk.Tk()
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1822, in __init__
self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment variable
Why is the DISPLAY variable invalid? If I execute the script manually (as I stated in the top) in the shell /bin/sh
that used by the batch job, it works.