Results 1 to 5 of 5

Thread: Adding a task to CRON ?

  1. #1
    Join Date
    Jul 2007
    Location
    Base 211
    Beans
    340
    Distro
    Ubuntu 14.04 Trusty Tahr

    Adding a task to CRON ?

    ok, have a service which seems to die often..

    I'm curious how to add my script that checks if its running and restart it if required...

    Im stumped as to how to add it to cron - to check every 20seconds..

    is anyone able to help.?

  2. #2
    Join Date
    Dec 2009
    Location
    germany
    Beans
    1,020
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Adding a task to CRON ?

    hi
    cron only knows minutes, hours, .... etc.
    for seconds you can write your own little script:
    while : ; do start_your_script & ; wait ; restart_your_script; done &

    ciao
    "What is the robbing of a bank compared to the FOUNDING of a bank?" Berthold Brecht

  3. #3
    Join Date
    Aug 2008
    Beans
    18

    Re: Adding a task to CRON ?

    The relevant line would be something like this
    Code:
    */20 * * * * /usr/bin/somedirectory/somecommand
    But that would be minutes. What I suggest is to use/write an upstart script that starts at boot and then checks things out every 20 seconds.

    Cheers!
    Last edited by Johnneylee; May 21st, 2010 at 09:33 AM. Reason: Lack of comprehension

  4. #4
    Join Date
    Jul 2007
    Location
    Base 211
    Beans
    340
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Adding a task to CRON ?

    Im no good at writing any type of scripts apart from ultra basic scripts.... so im stumped as how to approach this...

  5. #5
    Join Date
    Jul 2007
    Location
    Base 211
    Beans
    340
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Adding a task to CRON ?

    solved... didnt use cron..

    using something more crude..


    Code:
    #!/bin/bash
    RESTART="/etc/init.d/myscript.service start"
    PGREP="/usr/bin/pgrep"
    while true
    do
        $PGREP mjpg_streamer || $RESTART 
        sleep 20
    done

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •