在Ubuntu中,你可以使用cron来定时运行程序
打开终端(快捷键:Ctrl + Alt + T)。
输入以下命令,以编辑当前用户的crontab文件:
crontab -e
* * * * * /path/to/your/command arg1 arg2
| | | | |
| | | | ----- Day of week (0 - 7) (Sunday to Saturday; 7 is also Sunday)
| | | ------- Month (1 - 12)
| | --------- Day of month (1 - 31)
| ----------- Hour (0 - 23)
------------- Minute (0 - 59)
例如,如果你想要每天早上6点运行一个名为my_script.sh的脚本(位于/home/username/scripts/目录下),你可以添加以下行:
0 6 * * * /home/username/scripts/my_script.sh
注意:确保你的脚本具有可执行权限。如果没有,可以使用以下命令添加可执行权限:
chmod +x /path/to/your/script
如果你想要查看当前用户的crontab任务列表,可以使用以下命令:
crontab -l