aisensiy
aisensiy

Reputation: 1520

Why not the cron run?

I want to create a cron task in my debian system.

I do this

sudo crontab -e

and add a line

10 17 * * * /home/userdir/cron/meiwei-slide-shoot.sh

And I do this at 17:00 and hope the script run at 17:10. But it doesnt work.

I have tried the script. It works well. But why not it run by cron?

Upvotes: 1

Views: 111

Answers (2)

Brian Agnew
Brian Agnew

Reputation: 272417

I would

  1. check those file permissions to make sure the script can be executed by the cron user
  2. log the stdout / stderr to a file to capture any errors e.g. script.sh >/tmp/cron.log 2>&1

cron processes run with a hugely cut-down environment and it's likely that you've either got execute permission issues or you're relying on an environment variable that isn't available. For what it's worth I always go through a couple of iterations each time I set up a cron job.

This AskUbuntu question also contains some useful info.

Upvotes: 1

paxdiablo
paxdiablo

Reputation: 882566

Have you checked that the file is executable?

Have you added a line like:

touch /tmp/proof_that_i_am_running

to the top of the script to check whether it's starting, and just dropping out for some other reason, like an incomplete environment setup?

Have you received mail from cron containing the output/error?

Have you checked in the cron spool directory (such as /var/spool/cron/crontabs) to ensure the entry has been created?

There are a large number of things you could have missed, that's just the common ones, but a good start.


A good test is to add:

* * * * * date >>/tmp/crondates 2>&1

to your crontab and watch to see if that file appears.

Upvotes: 1

Related Questions