linux crontab 定时任务脚本

啥,这么多年居然没有写过这种脚本。。应一个兄弟请求,帮忙写个每天定时下载的任务脚本,记录如下:

 

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
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值