0

I've been trying to run a crontab command but it isn't running for some reason. The command is supposed to send push notifications.

My sudo crontab -e looks like this:

 0 0 * * 0 /home/[user]/resetWeeklyLeaderboard
 * * * * * /home/[user]/pushDelivery

I have a file called pushDelivery at the location above which contains the following:

 /usr/bin/flock -n /home/[user]/PushChatServer/push/lockfile usr/bin/php /home/[user]/PushChatServer/push/push.php development

I have also made pushDelivery executable by doing chmod +x pushDelivery. This code works perfectly for my resetWeeklyLeaderboard file but won't call the pushDelivery file.

It works if I run

 /home/[user]/pushDelivery 

It works if I run

 /usr/bin/flock -n /home/[user]/PushChatServer/push/lockfile usr/bin/php /home/[user]/PushChatServer/push/push.php development

However if in crontab I do

 * * * * * /home/[user]/pushDelivery

or

 * * * * * /usr/bin/flock -n /home/[user]/PushChatServer/push/lockfile usr/bin/php /home/[user]/PushChatServer/push/push.php development

it doesn't work. Please help me. Thank you!

UPDATE:

It still doesn't work but I've tried more stuff. I tried reversing the order in the crontab

 * * * * * /home/[user]/pushDelivery
 0 0 * * 0 /home/[user]/resetWeeklyLeaderboard

it doesn't work. I also tried making my resetWeeklyLeaderboard code run minutely

 * * * * * /home/[user]/pushDelivery
 * * * * * /home/[user]/resetWeeklyLeaderboard

and that works for my resetWeeklyLeaderboard code but not for my pushDelivery code. This implies to me that it is something in my pushDelivery code that is causing the issue. However I run /home/[user]/pushDelivery from command line and it works. What could be causing this problem?

user2012741
  • 89
  • 1
  • 8
  • What happens when you run `env -i /home/[user]/pushDelivery` ? – Jan Matějka Oct 10 '14 at 00:20
  • I get the error `/usr/bin/flock: usr/bin/php: No such file or directory` When I run `env -i /home/miguel/resetWeeklyLeaderboard` I don't get any errors. – user2012741 Oct 10 '14 at 12:50
  • Nevermind. I only get `/usr/bin/flock: usr/bin/php: No such file or directory` when I run `env -i /home/[user]/pushDelivery` from the /home/[user] directory. If I cd ../ to the top and run from there there is no error. Curiously though if I run `env -i /home/miguel/resetWeeklyLeaderboard` I become [trueuser] where as when I run `env -i /home/miguel/pushDelivery` I stay as [user]. – user2012741 Oct 10 '14 at 12:56

2 Answers2

0

i dont know why is is not running but same thing happens to me before at that time insted of doing
* * * * * /home/[user]/pushDelivery
try this
*/1 * * * * /home/[user]/pushDelivery
it worked for me in this way...(both the task run in every minute)

Deepak
  • 696
  • 4
  • 14
0

I fixed the issue. In my pushDelivery file I was supposed to write:

/usr/bin/flock -n /home/[user]/PushChatServer/push/lockfile /usr/bin/php /home/[user]/PushChatServer/push/push.php development

whereas I'd written:

/usr/bin/flock -n /home/[user]/PushChatServer/push/lockfile usr/bin/php /home/[user]/PushChatServer/push/push.php development

The "/" before the "usr/bin/php" makes all the difference. Somehow just that slash will allow it to work outside of crontab but will fail it when run inside crontab. I don't understand why but this is the correct solution.

user2012741
  • 89
  • 1
  • 8