0

Anybody any suggestions on why my crontab and shell script is not running.

I have

chmod +x my shell script and added the following into crontab -e

*/5 * * * * bash cd /home/jclark/scrips/ipcheck/ && ./ipCheck.sh

ipCheck.sh then costits of the following:

#!/bin/sh
curl http://api.externalip.net/ip/ -o ipRecord.txt

Although it doesn't appear to be running?

1 Answers1

2

You can't run bash commands like that. Bash expects a file (a shell script) .as its argument.

You might be able to run the desired command like this:

*/5 * * * * bash -c "cd /home/jclark/scrips/ipcheck/ && ./ipCheck.sh"

Note the -c and the quotes around the commands you want to execute.

I think that what you actually want is:

*/5 * * * * /home/jclark/scrips/ipcheck/ipCheck.sh

... and the script should contain:

#!/bin/bash
curl http://api.externalip.net/ip/ -o /home/jclark/scripts/ipcheck/ipRecord.txt
  • Thanks for the answer, the damn thing still doesn't seem to run! –  Dec 28 '12 at 16:45
  • @JacobClark Works for me on Ubuntu 12.10 exactly as I wrote it after the "what you actually want" part. –  Dec 28 '12 at 16:51
  • by running crontab -e? –  Dec 28 '12 at 16:52
  • @JacobClark Yep crontab -e is how I edited the crontab. I added it to the crontab, waited till the clock hit the right time, then checked and saw that the file was updated. Note that if you edit your crontab only a minute or two before it's supposed to trigger a job, the job probably won't be triggered. Wait another 5 minutes. –  Dec 28 '12 at 16:59
  • I have done exactly has shown but my Ubuntu 12.04 Rackspace Cloud Server just isn't running it –  Dec 28 '12 at 17:18
  • Are you sure crond is running? ps aux | grep crond | grep -v grep – Drake Clarris Dec 28 '12 at 18:39
  • I would use pgrep crond – waltinator Aug 24 '15 at 03:38