LinuxQuestions.org
Review your favorite Linux distribution.
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-02-2014, 01:45 PM   #1
bowser4
LQ Newbie
 
Registered: Sep 2014
Posts: 3

Rep: Reputation: Disabled
Script to reboot & start program as root?


Hi folks, I've posted in the newbie section as I'm relatively new to Linux, but thoroughly enjoying the learning curve. I'm running Lubuntu on an ancient laptop and I'm after a script which will run on booting, which will make the laptop reboot every couple of hours, and make a program run as root each time (yes, I know the dangers of running as root). Is such a thing possible?

Any advice welcomed.

Regards
 
Old 09-02-2014, 01:57 PM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 17,928

Rep: Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690
Quote:
Originally Posted by bowser4 View Post
Hi folks, I've posted in the newbie section as I'm relatively new to Linux, but thoroughly enjoying the learning curve. I'm running Lubuntu on an ancient laptop and I'm after a script which will run on booting, which will make the laptop reboot every couple of hours, and make a program run as root each time (yes, I know the dangers of running as root). Is such a thing possible?
Very possible. You'd have to kick the script off as root, and you could either use cron or at to schedule the job. Linux has a "reboot" command, and the shutdown command has options too (type in "man shutdown" for a list). So, construct your script to reboot using either method, after scheduling it to run again at whatever interval you want. You can either shove a line into crontab manually (since you're rebooting, cron will restart and pick up the new job), or use at to re-run the script.

An at job gives you a bit more flexibility, since you can say things like "at now + 2 hours /some/script", and it will run two hours from now.
 
Old 09-02-2014, 03:15 PM   #3
bowser4
LQ Newbie
 
Registered: Sep 2014
Posts: 3

Original Poster
Rep: Reputation: Disabled
Thankyou for your reply, its helpful. I'll start to put it together - how do I arrange the program to start, and as root please?
 
Old 09-02-2014, 03:34 PM   #4
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
Easiest option IMO is to use the @reboot directive in cron:

Code:
@reboot /path/to/script
If you put it in root's crontab, then it will run as root.

Last edited by suicidaleggroll; 09-02-2014 at 05:33 PM. Reason: typo
 
Old 09-02-2014, 04:23 PM   #5
bowser4
LQ Newbie
 
Registered: Sep 2014
Posts: 3

Original Poster
Rep: Reputation: Disabled
Sorry - could you explain 'roots crontab' - is this where I place the file & then chmod +x it?
 
Old 09-02-2014, 05:33 PM   #6
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
http://en.wikipedia.org/wiki/Cron
https://help.ubuntu.com/community/CronHowto
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
[SOLVED] halt & reboot commands without root gujedan Linux - Newbie 5 11-05-2011 03:23 PM
Which script start panel on reboot ? umang.gupta Linux - Laptop and Netbook 0 11-19-2008 12:58 AM
need a perl script to stop & start program cccc Programming 43 07-23-2005 08:27 PM
Using cron to start a program at reboot ? s&j Linux - General 2 06-22-2002 05:31 PM


All times are GMT -5. The time now is 10:42 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration