LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   need help writing a script (https://www.linuxquestions.org/questions/linux-newbie-8/need-help-writing-a-script-809415/)

puzzled_one 05-22-2010 01:25 AM

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...

EricTRA 05-22-2010 02:00 AM

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

grail 05-22-2010 02:01 AM

You could throw the 'sleep' command in your script.

puzzled_one 05-22-2010 02:07 AM

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


grail 05-22-2010 02:56 AM

Code:

while 1
do
    $PGREP mjpg_streamer || $RESTART
    sleep 20
done


puzzled_one 05-22-2010 03:08 AM

Quote:

Originally Posted by grail (Post 3977339)
Code:

while 1
do
    $PGREP mjpg_streamer || $RESTART
    sleep 20
done


launching from terminal i get

Code:

mjpg-restarter.sh: 7: 1: not found

grail 05-22-2010 03:57 AM

My bad, forgot the brackets. Place some round brackets around the 1

catkin 05-22-2010 04:22 AM

Or use while true

puzzled_one 05-22-2010 06:12 AM

Thanks for the help guys...

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


Cheers guys


All times are GMT -5. The time now is 06:14 PM.