LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 06-05-2009, 09:36 AM   #1
bmpenev
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:

vgaSignal.sh:

Code:
while [ 1 ]

do

# 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"

then
    echo Recieving Signal       

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

sleep 2

done
recording.sh:

Code:
while [ 1 ]

do

# Check if mencoder is running

if pidof mencoder

then
    echo Running

# If not, start it whith the appropriate settings

else
   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:// 

fi

sleep 2

done
/etc/rc.local:

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

chmod 777 /dev/vga2usb0

/bin/sh /home/stream/scripts/recording.sh

/bin/sh /home/stream/scripts/vgaSignal.sh

exit 0
Best regards,

bmpenev
 
Old 06-05-2009, 11:46 AM   #2
secesh
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:
Code:
#!/bin/bash
Then modify your rc.local:
Code:
/home/stream/scripts/recording.sh&
/home/stream/scripts/vgaSignal.sh&
-- 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.
 
  


Reply



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

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 08:00 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
Open Source Consulting | Domain Registration