Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 06-05-2009, 09:36 AM   #1
LQ Newbie
Registered: Jun 2009
Posts: 1

Rep: Reputation: 0
Bash script does not behave the same when executed through /etc/rc.local

Hello Everybody!

I have tried to develop a script, which automatically records video files from a usb capture device ( it is a Vga to usb capture device) at system start- up. The script should also restart the Encoding application and proceed with the recording, if the Vga source is being changed. I have tried to develop a pair of scripts: The first starts Mencoder and restarts it, if Mencoder gets interrupted. The second looks after the Vga source and interrupts Mencoder, if there is no singal. Due to me being pretty inexperienced, the code is pretty lame, but when i run both scirpts in a shell- everything works fine: Regardless of how often i pull and reinsert the vga cable- it restarts Mencoder and begins to record a new avi- file. When i run both scripts through /etc/rc.local however, the video gets recorded to the same same file after i pull and reinsert the plug. Furthermore- it stops recording alltogether after the third test of reinserting the cable.

I will be greatful for any help.

If it has any relevance, i am running Ubuntu 9.04 Here are the scripts:

while [ 1 ]


# Check if the capture device is recieving signal
# This is done by reading the otput of an application provided by the vendor
# Possible outputs: "v2u: detected 1024x768 (60.0 Hz)" if there is a vga signal, or 
# "v2u: failed to detect video modea" if there is no signal

if /home/stream/v2u | grep "v2u: detected"

    echo Recieving Signal       

# If not- kill mencoder, so that the other script could do a restart
     killall mencoder

sleep 2


while [ 1 ]


# Check if mencoder is running

if pidof mencoder

    echo Running

# If not, start it whith the appropriate settings

   mencoder \
        -oac lavc \
        -ovc lavc \
        -lavcopts vcodec=mpeg4:keyint=100:vbitrate=8000:vhq -noaspect \
        -o /home/stream/Recording_from_`date +%Y%m%d-%H%M%S`.avi \
        -tv noaudio:driver=v4l:outfmt=bgr24:device=/dev/video0 tv:// 


sleep 2


# By default this script does nothing.
cd /home/stream/vga2usb/ && make load

chmod 777 /dev/vga2usb0

/bin/sh /home/stream/scripts/

/bin/sh /home/stream/scripts/

exit 0
Best regards,

Old 06-05-2009, 11:46 AM   #2
Senior Member
Registered: Sep 2004
Location: Savannah, GA
Distribution: Ubuntu, Gentoo, Mythbuntu, ClarkConnect
Posts: 1,154

Rep: Reputation: 47
at the top of each of your source files, put:
Then modify your rc.local:
-- it looks like you're trying to have these things run in an infinite loop = they need to be in the background. That's what the '&' does.


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 On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script runs different when cron executed jalder85 Linux - Server 4 02-20-2009 11:53 AM
/etc/rc.local is not executed abd_bela Debian 1 02-08-2009 03:06 PM
LXer: Updated Bash Script To Get Cable, Dish and Local TV Listings LXer Syndicated Linux News 0 11-10-2008 12:20 PM
bash - start remote script from local script? babag Programming 7 04-06-2008 05:46 PM
bash script - I want some time delay between each command is executed bbmak Linux - Newbie 2 12-21-2007 03:35 AM > Forums > Linux Forums > Linux - General

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

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration