我已经为下面列出的我的网站创建了 cron 作业,它们运行良好。我使用此 PHP 脚本打印所有 cron 作业:
$cronfiles=exec('crontab -l',$output);
echo "<pre>";
print_r($output);
Run Code Online (Sandbox Code Playgroud)
哪些输出:
[0] => 0 0 * * * wget php -q http://www.example.com/report_send.php
[1] => 0 0 * * * wget php -q http://www.example.com/event_reminder.php
[2] => 0 0 * * * wget php -q http://www.example.com/user_reminder.php
[3] => * * * * * wget php -q http://www.example.com/cleardata.php
现在我想通过命令从我的服务器中删除或删除单个 cron 作业。例如,我想0 0 * * * wget php -q http://www.example.com/event_reminder.php从服务器中删除 cron 作业“ ”。
我尝试了crontab -r从我的服务器中删除所有 cron 作业的命令,但我想删除特定的 cron 作业。
你能帮我解决吗?
小智 101
向 crontab 添加作业:
(crontab -u mobman -l ; echo "*/5 * * * * perl /home/mobman/test.pl") | crontab -u mobman -
Run Code Online (Sandbox Code Playgroud)要从 crontab 中删除作业:
crontab -u mobman -l | grep -v 'perl /home/mobman/test.pl' | crontab -u mobman -
Run Code Online (Sandbox Code Playgroud)从 crontab 中删除所有内容:
crontab -r
Run Code Online (Sandbox Code Playgroud)没有什么是棘手的:-是 Linux 中的 STDOUT!
Rin*_*ind 36
From a root prompt type
crontab -e
Run Code Online (Sandbox Code Playgroud)
You can now edit the file and remove the line you want remove. You can also use this to edit crontab for users if you have the prompt for that user.
By the way: I prefer to add cronjobs to /etc/crontab. Seems a bit more flexible to me.
Waq*_*leh 12
使用以下语法查看waqleh用户的 cronjob:
crontab -u waqleh -l
Run Code Online (Sandbox Code Playgroud)
只需键入以下命令:
crontab -l
Run Code Online (Sandbox Code Playgroud)
crontab -u USERNAME -l
Run Code Online (Sandbox Code Playgroud)
这应该列出 crontab 脚本的内容。
cronjob 也可以从 /etc/crontab 文件运行。要查看它,请输入:
less /etc/crontab
Run Code Online (Sandbox Code Playgroud)
当且仅当您想停止所有 cron 作业时,您可以使用以下命令完全删除它们:
crontab -r
Run Code Online (Sandbox Code Playgroud)
这将删除当前用户的整个 crontab 文件,因此如果您在其中列出了其他 cron 作业,请小心!
crontab -e
Run Code Online (Sandbox Code Playgroud)
crontab -u USERNAME -e
Run Code Online (Sandbox Code Playgroud)
每行代表一个 cron 作业。您可以删除任何 cron(如果您通过单击 ctrl+k 使用 nano),然后保存并退出
小智 6
crontab -l | grep -v 'wget php -q http://www.example.com/event_reminder.php' | crontab -
Run Code Online (Sandbox Code Playgroud)
crontab -l列出当前的 crontab 作业
grep -v过滤一些行
crontab -将所有打印的内容添加到 crontab 文件中。