#!/bin/bash# 不知道要不要加环境变量, 鸟哥上说要.#PATH=/home/linxd/bin:/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games#export PATHdate >> "/home/linxd/Desktop/test.txt"
Linux设置定期执行脚本crontab用法 : 千万千万要记住, 不只是/etc/crontab中要用绝对路径, 连脚本也要用绝对路径
# /etc/crontab: system-wide crontab# Unlike any other crontab you don't have to run the `crontab'# command to install the new version when you edit this file# and files in /etc/cron.d. These files also have username fields,# that none of the other crontabs do.SHELL=/bin/shPATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin# m h dom mon dow user command17 * * * * root cd / && run-parts --report /etc/cron.hourly25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )*/1 * * * * linxd /home/linxd/Desktop/test.sh
定时脚本没能正确执行:
- 默认情况下 cron jobs 的 log 在 /var/log/syslog,可以通过 grep CRON /var/log/syslog 来查看【1】。
- 对于具体执行是否正确以及脚本执行过程中的一些信息,Linux会通过邮件形式发送到该用户【2】,邮件信息信息在 /var/mail/panjinbo
定时脚本调用GUI:
因为这个脚本需要调用Haroopad(GUI)来进行MD文本的编辑,但是Xhost默认不允许别的图形程序显示在当前屏幕上。出现的错误是这样子的:
`[14720:1104/195401:ERROR:browser_main_loop.cc(162)] Running without the SUID sandbox! `
`[14720:1104/195401:ERROR:browser_main_loop.cc(208)] Gtk: cannot open display: `
解决方案:ubuntu 下使用crontab定时执行java程序
在shell脚本程序GUI命令行之前,加入如下代码:export DISPLAY=:0.0 #启动GUI显示
#!/bin/bash# 不知道要不要加环境变量, 鸟哥上说要.#PATH=/home/linxd/bin:/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games#export PATHdate >> "/home/linxd/Desktop/test.txt"
Linux设置定期执行脚本crontab用法 : 千万千万要记住, 不只是/etc/crontab中要用绝对路径, 连脚本也要用绝对路径
# /etc/crontab: system-wide crontab# Unlike any other crontab you don't have to run the `crontab'# command to install the new version when you edit this file# and files in /etc/cron.d. These files also have username fields,# that none of the other crontabs do.SHELL=/bin/shPATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin# m h dom mon dow user command17 * * * * root cd / && run-parts --report /etc/cron.hourly25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )*/1 * * * * linxd /home/linxd/Desktop/test.sh
定时脚本没能正确执行:
- 默认情况下 cron jobs 的 log 在 /var/log/syslog,可以通过 grep CRON /var/log/syslog 来查看【1】。
- 对于具体执行是否正确以及脚本执行过程中的一些信息,Linux会通过邮件形式发送到该用户【2】,邮件信息信息在 /var/mail/panjinbo
定时脚本调用GUI:
因为这个脚本需要调用Haroopad(GUI)来进行MD文本的编辑,但是Xhost默认不允许别的图形程序显示在当前屏幕上。出现的错误是这样子的:
`[14720:1104/195401:ERROR:browser_main_loop.cc(162)] Running without the SUID sandbox! `
`[14720:1104/195401:ERROR:browser_main_loop.cc(208)] Gtk: cannot open display: `
解决方案:ubuntu 下使用crontab定时执行java程序
在shell脚本程序GUI命令行之前,加入如下代码:export DISPLAY=:0.0 #启动GUI显示
本文介绍如何在Linux环境下使用CronTab进行定时任务的设置,并确保脚本的正确执行。此外,还讨论了如何解决定时任务中调用GUI应用程序遇到的问题。
4084

被折叠的 条评论
为什么被折叠?



