LinuxQuestions.org
Help answer threads with 0 replies.
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 03-20-2012, 11:11 PM   #1
rmfinsmt
LQ Newbie
 
Registered: Mar 2012
Posts: 3

Rep: Reputation: Disabled
Can not run reboot script when program started thru rc.local


I am running Fedora 14 and starting a c program from rc.local My program can request a system reboot from a script called rebootscript.sh that has been copied to the current working directory, also to the root/bin directory as well as to a user/bin directory. (I'm desperate... what can I say)

the program calls the script with

strcpy(name,"sudo /bin/sh rebootscript");
system( name);

The rebootscript is as follows:

#!/bin/sh

clear
sudo reboot

If I manually start the c program after the system boots up, it works fine. If I start the c program from rc.local it does not work. The only difference I see is that when starting from rc.local, root is the owner. When starting manually after boot, the user is the owner of the process.

What am I missing???
thanks for any help
 
Old 03-20-2012, 11:23 PM   #2
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4852Reputation: 4852Reputation: 4852Reputation: 4852Reputation: 4852Reputation: 4852Reputation: 4852Reputation: 4852Reputation: 4852Reputation: 4852Reputation: 4852
I am no expert on this, but when the program runs from rc.local it is run as root, as you already pointed out. That makes the call with sudo unnecessary and may be this interferes somehow with the execution of the program. What happens if you start it manually from the command-line as root? Also, what happens if you start it from rc.local as a normal user?
 
Old 03-21-2012, 12:01 AM   #3
ozanbaba
Member
 
Registered: May 2003
Location: Tengiz
Distribution: Slackware64 14.1
Posts: 673

Rep: Reputation: 94
Quote:
Originally Posted by rmfinsmt View Post
I am running Fedora 14 and starting a c program from rc.local My program can request a system reboot from a script called rebootscript.sh that has been copied to the current working directory, also to the root/bin directory as well as to a user/bin directory. (I'm desperate... what can I say)

What am I missing???
thanks for any help
Try using full paths in the script.
 
Old 03-21-2012, 09:11 AM   #4
rmfinsmt
LQ Newbie
 
Registered: Mar 2012
Posts: 3

Original Poster
Rep: Reputation: Disabled
TobiSGD
Thanks for your response. I originally call the script without the 'sudo' and also without the '/bin/sh' (just the 'rebootscript'). None of these worked when the C program was started from the rc.local file.

I will try starting it from the command line as root.

How would I start the C program in the rc.local file with a different owner than root?
 
Old 03-21-2012, 09:27 AM   #5
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Quote:
Originally Posted by rmfinsmt View Post
How would I start the C program in the rc.local file with a different owner than root?
su <user name> <path to compiled and linked C program>
or, if you want to run the different user's logon shell's logon initialisation:
su - <user name> <path to compiled and linked C program>
 
Old 03-26-2012, 03:13 PM   #6
rmfinsmt
LQ Newbie
 
Registered: Mar 2012
Posts: 3

Original Poster
Rep: Reputation: Disabled
Thanks to all.
I tried the su <user name> <path to compiled and linked C program>, without success. The /var/log/boot.log and messages files kept identifing the rc.local had a compatability problem. Never could get around that.
I have found an easier way to reboot my system from a c program. I just use system("init 6") in the c program and it works every time whether the c program was started with the rc.local file or manually after booting and login in.
Again thanks for the suggestions.
 
  


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
script under /etc/init.d can not be started by reboot thomas2004ch Linux - Software 4 11-15-2011 06:22 AM
Run script on shutdown or reboot VeeDubbs Linux - Server 1 10-23-2008 02:34 PM
Configuring a program or script to run when KDE (or X) is started dizzi Slackware 2 05-31-2007 01:46 PM
clamd upgradation in remote mach through local mac by script to be run on local mach Narayandutt Programming 3 11-29-2006 11:00 AM
Make a script run at reboot Braynid Linux - Newbie 10 06-26-2006 11:10 AM

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

All times are GMT -5. The time now is 02:32 PM.

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