linux 脚本 定时,为linux添加计划任务(定时脚本)

因为经常要在机房上实验课,便想在机房远程自己的电脑。

但是我们学校的ruijie是在8点才能认证的,于是便编写了个自动执行的脚本,在8点连接上ruijie。

环境:ubuntu12.04

首先,编写一个脚本test.sh,保存在/home/nevermore目录,代码如下:

#!/bin/sh

sudo mentohust

echo success

这个脚本用于启动ruijie

接着,我们打开/etc/crontab,我们可以看到如下内容:

# m h dom mon dow usercommand

17 ** * * root    cd / && run-parts --report /etc/cron.hourly

25 6* * * roottest -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )

47 6* * 7 roottest -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )

52 61 * * roottest -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )

其中,m代表分钟,h代表小时,dom为day of month mon为月份 dow为day of week,我们在最后一行添加如下代码:

10 8       * * * root sudo /home/nevermore/test.sh

代表 系统将在每天的8点10分执行该目录下的test.sh脚本。

哈哈,ok,到此就完成操作啦~~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值