LinuxQuestions.org
Register a domain and help support LQ
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 06-29-2005, 06:56 AM   #1
dazz
LQ Newbie
 
Registered: Apr 2005
Posts: 22

Rep: Reputation: 15
Starting a Script from rc.local


Hello

I am trying to start a small script automatically on boot-up. The script simply configures, then starts a webcam frame grabber. The script is called webcam.sh and I want it to run under the <webcam> user rather than root.

I am running Redhat 9.

I have tried adding the following commands to rc.local :


echo "$Starting webcam"
su -c webcam "/user/webcam.sh"


I can see the echo message displayed, but the webcam script doesn't seem to run. The webcam.sh will run manually from the command line.

should these come before, or after the "touch" command in the rc.local file?

What am I missing?

any help much appreciated.
 
Old 06-29-2005, 07:49 AM   #2
hyllplan
Member
 
Registered: Nov 2004
Location: Stockholm, Sweden
Distribution: Debian (Sarge), Red Hat, Ubuntu, Knoppix
Posts: 99

Rep: Reputation: 15
Try su -c "/user/webcam.sh" webcam
 
Old 06-30-2005, 05:52 AM   #3
dazz
LQ Newbie
 
Registered: Apr 2005
Posts: 22

Original Poster
Rep: Reputation: 15
Thanks,

I tried:

su --login -command="/usr/webcam.sh" webcam

that only worked only for root user and not webcam user.

I got a permission denied on the video0 device.

The webcam.sh works when I manually log-in as webcam and run the webcam.sh

ls -l show

video0 crw------- 1 root root

I don't really want to run the webcam.sh as root.

Any ideas on solving the permissions issue?
 
Old 06-30-2005, 06:50 AM   #4
hyllplan
Member
 
Registered: Nov 2004
Location: Stockholm, Sweden
Distribution: Debian (Sarge), Red Hat, Ubuntu, Knoppix
Posts: 99

Rep: Reputation: 15
Create a group for the video0 device e.g. video

Add this group to the video0 device:
chown root:video /dev/video0

Change the permissions on video0 to let the group video get some rights for the file
chmod 660 /dev/video0

Add the user webcam to the group video

Logoff/logon before try it out
 
Old 07-01-2005, 05:51 AM   #5
dazz
LQ Newbie
 
Registered: Apr 2005
Posts: 22

Original Poster
Rep: Reputation: 15
Great. That worked OK.

The next problem I have is that the webcam.sh never stops running. I put an echo comment after the webcam.sh command and it is never displayed. This means the rc.local script never completes, so effectively the boot process never fully completes. I can't open any terminals. I have to alt-ctrl-del to regain control (by using interactive start-up and not allowing rc.local to run.

Do I need to run the webcam.sh as a background process?
 
Old 07-01-2005, 11:52 AM   #6
hyllplan
Member
 
Registered: Nov 2004
Location: Stockholm, Sweden
Distribution: Debian (Sarge), Red Hat, Ubuntu, Knoppix
Posts: 99

Rep: Reputation: 15
do you have an exit at the end of your script?
can I have a look at the line that executes the script?
can I have a look at your script?
 
Old 07-02-2005, 03:30 AM   #7
dazz
LQ Newbie
 
Registered: Apr 2005
Posts: 22

Original Poster
Rep: Reputation: 15
I seem to have found a solution.

The application outputs status to the terminal, so it needs to be assigned to one. It uses the hup signal to close the program when the assigned terminal is closed, but the code doesn't check to see if a terminal is assigned when it is opened. So I think when I ran the app from an rc.local script, it didn't have an assigned terminal and spat the dummy as soon as it tried to output script.

I used the command:

nohup <command> &

within the script called by the rc.local script to start the webcam running in the background. This creates a file to which the "terminal" output is directed. It effectively switches off the signal hup detection within the code. The signal detection means simply redirectlng output to null would NOT work.

So I now have something that works but I don't know if it is the best way. I suppose I could modify the code to send text output to a file rather than the terminal when no terminal is assigned, but I don't know much about C and Linux.
 
Old 07-02-2005, 05:20 AM   #8
hyllplan
Member
 
Registered: Nov 2004
Location: Stockholm, Sweden
Distribution: Debian (Sarge), Red Hat, Ubuntu, Knoppix
Posts: 99

Rep: Reputation: 15
To redirect standard-out (1) and standard-error (2) to a file you could write:
'command >file.out 2>&1'. That means; "put standard-out in file.out and put standard-error in the same place as standard-out".
There is also a device called /dev/null that you could redirect to, if you do that everything redirected to that device will simply just be thrown away, trashed, deleted. Its good sometime when you do not want to save the output, and you dont want it to show up on the console.
Thats right putting a '&' in the end backgrounds the process but I cannot see why you would use it in this case, dont you want to see whats happening during boot?
'nohup' is usually used if you e.g. want to start a script and then logoff, terminate your terminal, and you still want your script to continue running, thats why nohup redirects is output to a file as you say.
Kind Reg,
- Johan
 
Old 07-02-2005, 09:52 PM   #9
dazz
LQ Newbie
 
Registered: Apr 2005
Posts: 22

Original Poster
Rep: Reputation: 15
I started off with a single command in the rc.local file that called my webcam script. The webcam script has two commands. One to initiate the webcam settings, the next runs Linuxcam, a command line frame grabber.

The Linuxcam command doesn't exit to the prompt until the program is terminated (ctrl-C). In addition, the code terminates on the hup signal when the associated terminal is closed.

Based on a very fragile knowledge of Linux:

I need to background the Linuxcam program so the script will complete and exit to complete the rc.local script (otherwise the boot process never completes).

I need to make sure the output of the Linuxcam app has somewhere to go. nohup does that by creating an output file.

I assume that being Linux, there is probably a dozen ways of doing all this, so any suggestions would be welcome.
 
Old 07-03-2005, 06:03 AM   #10
hyllplan
Member
 
Registered: Nov 2004
Location: Stockholm, Sweden
Distribution: Debian (Sarge), Red Hat, Ubuntu, Knoppix
Posts: 99

Rep: Reputation: 15
Every way is great, as long as it works! :-)
- Johan
 
  


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
starting services using rc.local supersucker Linux - Newbie 8 11-03-2005 12:05 PM
Starting vncserver at boot using rc.local promethious Linux - General 3 10-14-2005 08:57 AM
Starting stunnel with rc.local Apollo77 Linux - General 1 11-28-2004 01:00 AM
rc.local not starting my application Greenman Linux - Newbie 11 08-17-2004 04:35 PM
iptables & rc.local starting script = applications are slowing down. immer Linux - Networking 3 12-13-2003 10:11 AM


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