I have been trying to get a shell script to run for hours using cron to no avail. I am trying to have the following bash script run every minute

ps cax | grep 'ices' > /dev/null
if [ $? -eq 0 ]; then
  echo "Process is running."
  /usr/local/bin/ices /etc/ices/playlist.pls

It checks if a process is running, and if not reloads it. It works as an executable (permissions are set to 755).

My crontab looks like

    # m h  dom mon dow   command
    */1   *    *    *    *    /etc/ices/checkIces.sh
    */1   *    *    *    *    env > /tmp/env.output

The second line is to check if cron will at least log out the env in the tmp folder. Does anyone see anything wrong with my current implementation?

  • If you want it to run every minute, use * * * * * somecommand – DopeGhoti Jan 14 '14 at 4:33
  • What gets written to /tmp/env.output ? – Kent Jan 14 '14 at 4:49
  • The output for checkIces.sh should be mailed to you. Add a line to your checkIces.sh script to "touch $HOME/.checkIces.sh-isrunning", and then check to make sure that file is being updated at a minute resolution. The bigger problem is to get Ubuntu's mail working so when the crontab entry generates output to stdout or stderr, then that output will be properly mailed to you. Let me know when and how you get Ubuntu's mail working. That's what I'd like to know. ;-) – Billy McCloskey Jan 14 '14 at 5:05

Basically, this is a problem about getting enough info to perform debugging. I can offer the following suggestions.

The script looks fine, except that I would modify the PATH command as follows, just out of caution:


You should include this statement

  exec >>${0}.out 2>>${0}.out

into your small bash script. It redirects all output, standard and error, to a file which has the same name as the script, followed by .out. So, if your script is called my_script.sh, you will find all output into my_script.sh.out. Just make sure writing permissions allow the creation and modification of the file. You will find there error messages, which otherwise may get lost.

Third, try running the problem with the at command, instead of cron, for the moment. The difference lies in the environment. If the program runs with at, but fails with cron, you will know that you have to import some feature of your environment. Hopefully, the second suggestion will give you some hint there.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.