Find the answer to your Linux question:
Results 1 to 4 of 4
Hello I'll describe my problem I have my own server running which sometimes "crashes", so I thought I could check every minute and if its down - start it. I ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Mar 2011
    Posts
    3

    Crontab - running a scrtipt


    Hello

    I'll describe my problem I have my own server running which sometimes "crashes", so I thought I could check every minute and if its down - start it.

    I wrote a script

    Code:
    #!/bin/bash
    
    if ! lsof | grep 6011
    then /home/path/server config.xml
    fi
    
    exit 0
    Script is working If I run it manually, but if I run it through Cron.
    Code:
    crontab -e
    0-59 * * * * /home/path/server_enabler.sh
    its not working Cron itself is good, because i wrote simple script creating a file, and its ok. I tried to add & at the end to run it in the BG, but it didn't help. What could be the problem ?

  2. #2
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    3,390
    The issue is most likely environment.
    cron has a different one that your user.
    So you need to find out, what $PATH, etc your server needs.

    Other than that:
    It would be possible to implement the restart functionality via /etc/inittab.

    Other other than that
    The best option is to find out why this server crashes and fix that.
    You must always face the curtain with a bow.

  3. #3
    Just Joined!
    Join Date
    Mar 2011
    Posts
    3
    I copied my environment
    Code:
    env > .profile
    then found on he internet how to run cron, I tried
    Code:
    0-59 * * * *  /usr/bin/bash -c '. /home/myuser/.profile && /home/path/myscript.sh'
    and
    Code:
    0-59 * * * * [ -f /home/myuser/.profile ] && . /home/jimmy/.profile && /home/jimmy/cha/scripts/cekpderr
    But no response from the Cron (wish there was a error log or something)

    EDIT:
    I simplified script to
    Code:
    #!/bin/bash
    
    /home/path/server config.xml
    
    exit 0
    and still nothing.
    Last edited by Juzbrig; 03-31-2011 at 11:43 AM.

  4. #4
    Just Joined!
    Join Date
    Mar 2011
    Posts
    3

    Talking

    It works !
    I modified the script :

    Code:
    if ! lsof | grep 6011
    then 
    cd /home/sciezka/
    ./server konfig.xml
    fi
    Last edited by Juzbrig; 04-01-2011 at 11:20 AM.

Posting Permissions

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