- 論壇徽章:
- 0
|
腳本名為hc.py
root@gmcdmas1o> ls -l
total 38
-rwxr-xr-x 1 hai nms 15877 May 9 15:46 hc.py
crontab名為:
47 15 * * * /home/hai/hc/hc.py
直接在shell命令行執(zhí)行hc.py 能夠正常運行,
但是用crontab也能執(zhí)行,但只是執(zhí)行到
record_file.write('###############check cpu status########################\n')
report_file.write('###############check cpu status########################\n')
就再也不繼續(xù)執(zhí)行了。。
換過47 15 * * * python /home/hai/hc/hc.py也不行
求解答,謝謝!!
下面是程序示例:
#!/usr/bin/env python
import commands,time,os,glob
date_time=time.strftime('%Y%m%d%H%M%S',time.localtime())
host_name=commands.getoutput('hostname')
record_file1='%s%sHc_record.log' %(host_name,date_time)
report_file1='%s%sHc_report.log' %(host_name,date_time)
record_file=open(r'/home/zhaohai/hc/log/'+record_file1,'w+')
report_file=open(r'/home/zhaohai/hc/log/'+report_file1,'w+')
record_file.write('###############check cpu status########################\n')
report_file.write('###############check cpu status########################\n')
top_info1=commands.getoutput('top -n 20')
|
|