LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   using crontab to run scripts at boot (https://www.linuxquestions.org/questions/linux-newbie-8/using-crontab-to-run-scripts-at-boot-745381/)

JDska55 08-05-2009 03:17 PM

using crontab to run scripts at boot
 
Hey all-
I'm trying to hook a couple of scripts into the boot sequence of my ubuntu hardy machine. I entered the following line into the crontab

Code:

@reboot bash ~/monitor.sh
But it doesn't seem to be running when I boot it up. Does this command only run on reboots and not during startup from an off state?

Cheers,
Jarrod

pljvaldez 08-05-2009 03:21 PM

I think the proper place to put scripts for boot is in the init scripts. I think Ubuntu now uses the Upstart system, it used to use files in /etc/init.d. Not sure at what point that migration occurred, but those are your two best options.

repo 08-05-2009 03:32 PM

You can put your script in /etc/rc.local

Tinkster 08-05-2009 03:44 PM

I've never seen that syntax for a crontab before - where did you find that? :}

The "normal" way to do what you're trying to achieve would be to put
the script into /etc/init.d and make an appropriate symlink in rc1.d

JDska55 08-05-2009 04:07 PM

I found that particular crontab syntax here:
http://www.debianhelp.co.uk/crontab.htm
It seems like it would be pretty handy for things you want to run weekly, monthly, etc.

I'm trying out the init.d/rc1.d symlink setup for now. Hopefully this will be a bit more stable.

On a different note, I have an opinion question: The monitor script waits until another script (we'll call it configure.sh) arrives from a remote machine, and then runs it. Configure.sh then runs the two actual business scripts that I need. Does that sound like a reasonable method or is there a better way than daisy-chaining scripts like that?

EDIT: Hm. putting the monitor.sh script in /etc/init.d and creating a symlink to it called Smonitor in rc1.d doesn't seem to be working. I don't think it's running at all. Granted, I'm not sure, because I'm booting up a remote machine here, but since none of the output directories are getting created I think monitor.sh isn't getting executed on reboot. Do I need to change my script to accept a "start" argument like it says in the Debian policy manual?

Tinkster 08-05-2009 09:06 PM

Interesting ... which version the vixie cron is that?
The dillon one that comes with Slack 12.2 doesn't have the feature.


Cheers,
Tink

JDska55 08-06-2009 01:41 PM

Tink-
It appears that it's the 4th Berkeley Distribution, dated 31 October 2006. I can't find a specific version though. I have a bit of an different question for you- remember this while loop condition you gave me a month or so ago?

Code:

while $( ec2din --simple | awk 'BEGIN{flag=0}{if($0 ~ /pending/){flag++}}END{if ( flag > 0 ) {exit 0} else {exit 1}}' );
I have a changed version in my monitor.sh script, and I'm wondering if maybe I messed it up:

Code:

while $( find $PWD -name configure.sh | awk 'BEGIN{flag=0}{if($0 ~ /"/root/configure.sh"/){flag++}}END{if ( flag = 0 ) {exit 0} else {exit 1}}' );
  do
    sleep 30
  done

bash ~/configure.sh

What this is supposed to do is wait until configure.sh is transferred to it from a remote machine, and then execute configure.sh. I am wondering if the quotes in the if condition are throwing it off. Thoughts?

Tinkster 08-06-2009 09:49 PM

Two things with that:

a) strip the quotes. Escape the /'s with backslash:
Code:

/\/root\/configure.sh/
b) You're not comparing flag to zero, you're assigning 0 to flag:
Code:

flag == 0
instead of
Code:

flag =0

Cheers,
Tink


All times are GMT -5. The time now is 11:31 AM.