啥,这么多年居然没有写过这种脚本。。应一个兄弟请求,帮忙写个每天定时下载的任务脚本,记录如下:
1、编写任务的shell脚本
#! /bin/sh
workpath="/home/***/Downloads/";
cd $workpath;
dateStr=$(date -u +%Y%m%d);
fileName=top-${dateStr}.zip;
echo "$fileName";
filePath=${workpath}${fileName};
echo "$filePath";
while(true)
do
if [ -e "$filePath" ]
then
exit;
fi
wget http://s3.amazonaws.com/alexa-static/top-1m.csv.zip;
mv top-1m.csv.zip $fileName
done
2、编写crontab的脚本
*/1 * * * * /home/***/Downloads/downloadTopList.sh
3、启动crontab
命令:service cron start
如果出现
start: Rejected send message, 1 matched rules; type="method_call", sender=":1.94" (uid=1000 pid=6445 comm="start cron ") interface="com.ubuntu.Upstart0_6.Job" member="Start" error name="(unset)" requested_reply="0" destination="com.ubuntu.Upstart" (uid=0 pid=1 comm="/sbin/init")
是因为权限不够,sudo就ok了。好吧这个提醒也太隐晦了吧;
4、开机启动:
虽然默认是安装了crontab但是默认不启动,如需求开机启动需要
编辑“/etc/rc.local”,把启动程序的shell命令输入进去即可 如:将
sudo service cron start 添加到最后即可;
本站支持
pay for your wishes