首先創(chuàng)建一個php文件,用來執(zhí)行你的任務(wù)
#vi /home/a.php
<?php
$myfile = fopen("/home/test.txt", "a") or die("Unable to open file!");
$txt = date('Y-m-d H:i:s',time())."\n";
fwrite($myfile, $txt);
fclose($myfile);
?>
再創(chuàng)建一個test文本文件
#touch /home/test.txt
php 的準(zhǔn)備工作就完成了,下面配置crontab
找到PHP的執(zhí)行路徑
#whereis php

Paste_Image.png
然后配置crontab
# crontab -e

Paste_Image.png
這里是每一分鐘執(zhí)行一次 /home/a.php
啟動crontab
#service crond start然后看下有沒有想要的效果,查看test.txt 的內(nèi)容

Paste_Image.png