LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-05-2009, 03:17 PM   #1
JDska55
LQ Newbie
 
Registered: Jun 2009
Location: Iowa City, IA
Distribution: SuSE 11, ubuntu Hardy
Posts: 28

Rep: Reputation: 15
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
 
Old 08-05-2009, 03:21 PM   #2
pljvaldez
LQ Guru
 
Registered: Dec 2005
Location: Somewhere on the String
Distribution: Debian Wheezy (x86)
Posts: 6,094

Rep: Reputation: 281Reputation: 281Reputation: 281
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.
 
Old 08-05-2009, 03:32 PM   #3
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,529

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
You can put your script in /etc/rc.local
 
Old 08-05-2009, 03:44 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
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
 
Old 08-05-2009, 04:07 PM   #5
JDska55
LQ Newbie
 
Registered: Jun 2009
Location: Iowa City, IA
Distribution: SuSE 11, ubuntu Hardy
Posts: 28

Original Poster
Rep: Reputation: 15
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?

Last edited by JDska55; 08-05-2009 at 04:26 PM.
 
Old 08-05-2009, 09:06 PM   #6
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

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


Cheers,
Tink

Last edited by Tinkster; 08-05-2009 at 09:09 PM.
 
Old 08-06-2009, 01:41 PM   #7
JDska55
LQ Newbie
 
Registered: Jun 2009
Location: Iowa City, IA
Distribution: SuSE 11, ubuntu Hardy
Posts: 28

Original Poster
Rep: Reputation: 15
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?
 
Old 08-06-2009, 09:49 PM   #8
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot run important boot-up scripts retox Fedora 4 05-10-2007 02:09 PM
some cool crontab scripts djgerbavore Linux - Newbie 1 05-25-2005 09:14 AM
run network connection scripts on boot? BlackIce579 Linux - Networking 1 04-12-2004 10:03 PM
Can I re-run the first boot scripts? threethirty Linux - Laptop and Netbook 2 04-07-2004 11:29 PM
crontab and scripts Kent Emia Linux - General 6 10-02-2003 05:47 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:22 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration