6

I have created a ruby script file that checks the connection present or not. For example checking port 22 is opened or not.

Firstly I tried with cron job as follows

@reboot find ${HOME}/my_app/check_conn.rb

But it is executing immediately after starting the system.

Now I have to run this script after 5 or 10 min.

How can I do this. Is there any other way for doing this.

Thanks in advance.

4
  • 2
    A bad hack: Add sleep 600; to the beginning of the command.
    – Dan
    Jul 2, 2014 at 16:31
  • I would never execute from cron itself and always create an executable file in /etc/cronjob; Just put an at command inside that file to execute it 5 minutes from now?
    – Rinzwind
    Jul 2, 2014 at 16:31
  • @dan08 did I have to add sleep 600; before my cron_job or in my script file? Jul 3, 2014 at 7:31
  • @dan08, please post your comment as an answer. Jul 3, 2014 at 7:45

2 Answers 2

9

Add sleep 600; to the beginning of your crontab command to make it wait for 600 seconds before proceeding to the next step.

Your new crontab command would look like

@reboot sleep 600; find ${HOME}/my_app/check_conn.rb

2

Don't do it depending on time, but after establishing a network connection. The right place to do it is below:

/etc/network/if-up.d

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.