- 论坛徽章:
- 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命令行执行hc.py 能够正常运行,
但是用crontab也能执行,但只是执行到
record_file.write('###############check cpu status########################\n')
report_file.write('###############check cpu status########################\n')
就再也不继续执行了。。
换过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')
|
|