Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running bash script 10 minutes after the system start

I'm trying to run a bash script 10 minutes after my system startup and on every reboot. I was planning to the @reboot of crontab, but I'm not sure of two things

  • Whether it will run on the first system start or only on reboot.
  • How to delay the run by 10 minutes after the reboot.

What expression would suit my situation the best? Please note that I can't run 'at' or system timer to accomplish this as both are not accessible to us. I'm working on the RHEL 7..

like image 984
Naveen Balasubramanian Avatar asked Jan 02 '23 23:01

Naveen Balasubramanian


2 Answers

I would just sleep 600 at the beginning of your reboot script. Sure, there's probably a more "expert" way of doing it, but it'll work.

like image 141
user3243135 Avatar answered Jan 05 '23 13:01

user3243135


I think your question may be more appropriate on the Unix and Linux stack exchange, because I found two answers over there which directly address your question:

https://unix.stackexchange.com/questions/57852/crontab-job-start-1-min-after-reboot

Basically you can always just add sleep 600 to the beginning of your cronjob invocation.

As to whether you should be running a cronjob vs an init script:

https://unix.stackexchange.com/questions/188042/running-a-script-during-booting-startup-init-d-vs-cron-reboot

There are a handful of subtle differences, but basically, your cron @reboot will run each time the system starts and may be more easy to manage as a non-root user.

like image 30
JawguyChooser Avatar answered Jan 05 '23 14:01

JawguyChooser