Naveen Balasubramanian
Naveen Balasubramanian

Reputation: 671

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

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..

Upvotes: 5

Views: 12870

Answers (3)

JawguyChooser
JawguyChooser

Reputation: 1936

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.

Upvotes: 4

user3243135
user3243135

Reputation: 820

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.

Upvotes: 5

iamauser
iamauser

Reputation: 11489

rc-local.service would be better for your needs on a EL7 system.

  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)

You need to put your script that can run with any amount of delay inside the file, /etc/rc.d/rc.local, e.g.,

sleep 600 && /usr/local/bin/myscript.sh

OR you can put delay inside the script.

# 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

Upvotes: 0

Related Questions