Linux - NewbieThis 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!
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
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?
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?
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.
Distribution: Debian (Sarge), Red Hat, Ubuntu, Knoppix
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.
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.