我正在尝试在系统启动后10分钟和每次重启时运行bash脚本。我正计划到crontab的@reboot,但我不确定两件事
哪种表达最适合我的情况?请注意,我无法运行'at'或系统计时器来完成此操作,因为我们无法访问这两者。我正在研究RHEL 7 ..
答案 0 :(得分:3)
我只会在重启脚本的开头sleep 600
。当然,可能有一种更“专家”的方式,但它会起作用。
答案 1 :(得分:2)
我认为您的问题可能更适合Unix和Linux堆栈交换,因为我找到了两个直接解决您问题的答案:
https://unix.stackexchange.com/questions/57852/crontab-job-start-1-min-after-reboot
基本上,您只需将sleep 600
添加到cronjob调用的开头即可。
关于你是否应该运行cronjob与init脚本:
有一些微妙的差异,但基本上,你的cron @reboot将在每次系统启动时运行,并且可能更容易作为非root用户进行管理。
答案 2 :(得分:0)
rc-local.service
可以更好地满足您在EL7系统上的需求。
systemctl status rc-local.service
● rc-local.service - /etc/rc.d/rc.local Compatibility
Loaded: loaded (/usr/lib/systemd/system/rc-local.service; static; vendor preset: disabled)
Active: inactive (dead)
您需要将可以在文件/etc/rc.d/rc.local
内放置任何延迟的脚本放置,例如,
sleep 600 && /usr/local/bin/myscript.sh
或者你可以在脚本中加入延迟。
# Give exe permission to the local script as well as `rc.local`
chmod a+x /usr/local/bin/myscript.sh
chmod a+x /etc/rc.d/rc.local
# Enable the service. Note the service name has a `-` compared `.` in the file.
systemctl enable rc-local.service