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 05-22-2010, 02:25 AM   #1
puzzled_one
LQ Newbie
 
Registered: Mar 2010
Posts: 10

Rep: Reputation: 0
need help writing a script


ok here's the jist of the problem...

Im using mjpg_streamer for live video over a network, how-ever for some reason it gets buffer errors which i cannot seem to fix, no biggie, all that happens is the proccess quits, which kills the video feed..

I have made a service script that will check if the proccess is running and if it is it does nothing, if its not running, it'll restart it...

Now i wanted to add it to cron but thats pointless as cron works only every minute, not seconds..

Im wanting someone to help me write a simple script that will run the service i have created every 20 seconds or so...

I have no idea howto etc... the current script is one i found online and changed a few things too...

how do i go about this... google only returns info that is useless to me because i dont understand what they are trying to do etc...
 
Old 05-22-2010, 03:00 AM   #2
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295
Hello,

I think the simplest solution is to run your commands using a loop structure in combination with a sleep command. Have a look at this man page for sleep.

It might also help us if you post what you have got as script.

Kind regards,

Eric
 
Old 05-22-2010, 03:01 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,245

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
You could throw the 'sleep' command in your script.
 
Old 05-22-2010, 03:07 AM   #4
puzzled_one
LQ Newbie
 
Registered: Mar 2010
Posts: 10

Original Poster
Rep: Reputation: 0
here's my script - its also a service


Code:
#!/bin/bash
RESTART="/etc/init.d/myscript.service start"
PGREP="/usr/bin/pgrep"
$PGREP mjpg_streamer || $RESTART
 
Old 05-22-2010, 03:56 AM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,245

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
Code:
while 1
do
    $PGREP mjpg_streamer || $RESTART
    sleep 20
done
 
Old 05-22-2010, 04:08 AM   #6
puzzled_one
LQ Newbie
 
Registered: Mar 2010
Posts: 10

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by grail View Post
Code:
while 1
do
    $PGREP mjpg_streamer || $RESTART
    sleep 20
done
launching from terminal i get

Code:
mjpg-restarter.sh: 7: 1: not found
 
Old 05-22-2010, 04:57 AM   #7
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,245

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
My bad, forgot the brackets. Place some round brackets around the 1
 
Old 05-22-2010, 05:22 AM   #8
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
Or use while true
 
Old 05-22-2010, 07:12 AM   #9
puzzled_one
LQ Newbie
 
Registered: Mar 2010
Posts: 10

Original Poster
Rep: Reputation: 0
Thanks for the help guys...

got it working... using the 1 method didnt work, but swapping it for the "true" statement has....


Cheers guys
 
  


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
Help me in writing the script prakash.akumalla Linux - Newbie 7 12-19-2008 02:49 PM
Help writing with SH script? SirJinX Programming 1 01-24-2006 06:57 AM
writing a script mjl3434 Linux - Newbie 7 12-13-2005 12:40 AM
Help Writing a script. teeth44 Programming 2 10-14-2003 01:00 PM
writing a Script spanky5125 Linux - Security 5 01-08-2002 10:22 AM


All times are GMT -5. The time now is 02:13 AM.

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