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

在Ubuntu 12.04环境下,为了实现在每天8点远程连接机房的Ruijie设备,作者编写了一个名为test.sh的脚本,并通过编辑/etc/crontab文件设置每日8点10分执行该脚本,实现了自动认证的功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

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

环境:ubuntu12.04

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

#!/bin/sh

sudo mentohust

echo success

这个脚本用于启动ruijie

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

# m h dom mon dow user command
17 * * * * root    cd / && run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6 1 * * root test -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、付费专栏及课程。

余额充值