LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 09-08-2009, 02:11 PM   #1
ravedog
Member
 
Registered: Jun 2009
Distribution: Ubuntu, Sabayon
Posts: 38

Rep: Reputation: 0
Smile after power up i need a script started


Hey all!

A new day, a new question

I have a script that i would like to run once, 3-5 minutes after the machine starts up. Is anacron my friend here?

Any idéas?

Thanks in advance guys!

/ravedog
 
Old 09-08-2009, 03:18 PM   #2
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
No, it's better to use the at command.
 
Old 09-08-2009, 03:23 PM   #3
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556
I've never used the `at` tool, so it may be the right tool for the job, but I don't know.

But what about running the script (forking it off) directly from your rc.local init script (or your distro's equivalent init script) and inside your script, have a sleep loop of 300 seconds, after which it continues on to doing the actual good stuff?

Sasha
 
Old 09-08-2009, 03:32 PM   #4
ravedog
Member
 
Registered: Jun 2009
Distribution: Ubuntu, Sabayon
Posts: 38

Original Poster
Rep: Reputation: 0
@ bathory: I never checked out the at command, ill have a look at it. ty! EDIT: Had a quick look at the "at" command, isnt that only for starting stuff at a specific time? inned to start it directly after boot up, whenever that might be

@ GrapefruiTgirl: i run ubuntu 9.04, i understand what your saying here. Still im a abit scared of messing up there since i dont really know how to use it, could you elaborate on it?

Thanks for your quick replys guys!

Last edited by ravedog; 09-08-2009 at 03:35 PM.
 
Old 09-08-2009, 03:40 PM   #5
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556
Sure,

I don't use ubuntu, so there's probably a more appropriate way to do it on that OS, though the principle is the same.

Either:

A) inside one of the rc.d folders (or inside any that are relevant to your desired runlevels where you want your script executed)
OR
B) within an existing script as mentioned,

You would put a line like:

Code:
/path/to/your/script &
The & symbol makes the script fork off into the background, while the parent script continues along its merry way.

And now, the first line of your special script, would read:

Code:
sleep 300
which would induce a 5 minute delay before the rest of the script was executed.

Again, there's a "prefect" way to do this on Ubuntu, which another Ubuntu user will have to explain to you, about how to induce scripts to execute the correct way at bootup in various runlevels, using the init.d folders.

Good luck!
Sasha
 
Old 09-08-2009, 04:29 PM   #6
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
Quote:
@ bathory: I never checked out the at command, ill have a look at it. ty! EDIT: Had a quick look at the "at" command, isnt that only for starting stuff at a specific time? inned to start it directly after boot up, whenever that might be
No, you can also tell at to start after a specified amount of time. In you case you can put the following in rc.local
Code:
at -f /path/to/script now + 5 min
and it will run your script 5 minutes after rc.local is ran. You can verify it with atq.

Last edited by bathory; 09-08-2009 at 04:45 PM.
 
Old 09-08-2009, 05:51 PM   #7
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556
Quote:
Originally Posted by bathory View Post
No, you can also tell at to start after a specified amount of time. In you case you can put the following in rc.local
Code:
at -f /path/to/script now + 5 min
and it will run your script 5 minutes after rc.local is ran. You can verify it with atq.
Hey that's cool
 
Old 09-09-2009, 07:05 AM   #8
ravedog
Member
 
Registered: Jun 2009
Distribution: Ubuntu, Sabayon
Posts: 38

Original Poster
Rep: Reputation: 0
Thanks alot you guys. I really apreciate it!

br,

RavedoG
 
Old 09-16-2009, 12:38 PM   #9
ravedog
Member
 
Registered: Jun 2009
Distribution: Ubuntu, Sabayon
Posts: 38

Original Poster
Rep: Reputation: 0
hey again!

I just tried to put:
at -f /path/randomprogram now + 2 minutes

Just to see that everything was kicking and a process was staring. And it actually wasn't, i could see it with atq but it never start. I tried with a script that created a new file as well and it never started either.

Is there some special way to place the line in rc.local or is it just to ram it in there in there at the last line?

thanks in advance!

/R
 
Old 09-16-2009, 12:45 PM   #10
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
You can just put it in there. It will run with root privileges. OK? If not you can prefix it with the su command.
 
Old 09-16-2009, 04:49 PM   #11
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
Quote:
Just to see that everything was kicking and a process was staring. And it actually wasn't, i could see it with atq but it never start. I tried with a script that created a new file as well and it never started either.
You have to make sure that the atd daemon is running.
Quote:
Is there some special way to place the line in rc.local or is it just to ram it in there in there at the last line?
You can put the line where you want. Just to be sure, use the full path to the at command:
Code:
/usr/bin/at -f /path/randomprogram now + 2 minutes
Cheers
 
Old 09-17-2009, 11:59 AM   #12
ravedog
Member
 
Registered: Jun 2009
Distribution: Ubuntu, Sabayon
Posts: 38

Original Poster
Rep: Reputation: 0
Hey again!

Thanks alot for all help, still cant get it to work though.

Last trys just to see was that i ran:

/usr/bin/at -f /usr/bin/cvlc now +2 min
sudo myusername /usr/bin/at -f /usr/bin/cvlc now +2 min

Both of the starts just fine when i run them in the shell, none of them work when put i rc.local.

Maby this isnt working in ubuntu dist?

br,

Ravedog
 
Old 09-17-2009, 01:01 PM   #13
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
I guess you have to update your rc scripts, according to this.

Regards
 
Old 09-17-2009, 02:57 PM   #14
btncix
Member
 
Registered: Aug 2009
Location: USA
Posts: 141

Rep: Reputation: 26
Why would you need to have su or sudo in this case? Isn't the /path/to/your/script being called from rc.local which is run during the init process by the superuser, who would have full priviledges? So wouldn't the superuser execute /path/to/your/script at the appropriate time?
 
Old 09-17-2009, 03:04 PM   #15
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by btncix View Post
Why would you need to have su or sudo in this case? Isn't the /path/to/your/script being called from rc.local which is run during the init process by the superuser, who would have full priviledges? So wouldn't the superuser execute /path/to/your/script at the appropriate time?
Yes it would and presumably that is not what is wanted.
 
  


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
script command works unless started by udev kscott121 Linux - Software 2 12-31-2007 10:38 PM
kontact startup script - check if started pbhj Linux - Software 2 12-04-2006 03:41 PM
I have started working on a tutorial script kedens Linux - General 6 10-15-2006 04:48 PM
Priority of processes (using nice) started from within a script podollb Linux - Software 1 01-08-2006 11:44 AM
How Do I Have a script started at boot time? Chijtska Linux - General 12 03-18-2002 05:41 PM

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

All times are GMT -5. The time now is 05:53 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