crontab doesn't run the links2 command - linux

I'm trying run the following command every 1 minute using crontab, but the command doesn't run.
1 * * * * /usr/bin/links2 http://localhost/tomada/temperatura/servidor.php
The command works fine using the shell
What is the problem?

First -- don't use links for that purpose; it's built to be an interactive browser, but a cron job by its nature is noninteractive. curl is the right tool for the job:
* * * * * curl http://localhost/tomada/temperatura/servidor.php
...or, if you can't use curl (why?), then wget:
* * * * * wget -O - http://localhost/tomada/temperatura/servidor.php
Second -- if you must use links, use it in an explicitly noninteractive way, such as with -dump or -source:
* * * * * /usr/bin/links2 -dump http://localhost/tomada/temperatura/servidor.php

Related

Cronjobs do not run

I'm trying to run a cronjob to start and stop a server under a non-sudo user. I've tried asking others and doing what I saw from looking on google before asking here, but I'm still stuck.
Here's what's in my crontab for the server user:
* * * * * /home/server/startup/stop.sh
* * * * * /home/server/startup/start.sh
Here is what is in my stop.sh script:
#! /bin/sh
screen -r server -X quit
Everything runs normally if I run it using sh, and I only encounter a problem when using cron.
From what I see there could be 2 possible problems:
If the lines you are running in crontab are (and only those):
home/server/startup/stop.sh
home/server/startup/start.sh
then you are missing the time part of the line. If you want to run your program only once on boot you can run:
#reboot home/server/startup/start.sh
You are not giving the full path to your program (possibly you are just missing a / in the begging). Try running
* * * * * /home/server/startup/start.sh
or
#reboot /home/server/startup/start.sh
If these don't work I recommend you try the following to troubleshoot the issue:
Run the command using sh in the cron:
* * * * * /bin/sh /home/server/startup/start.sh
Try redirecting the stdout and stderr of your command to a file and see if any errors occur

Why is my crontab not working?

I'm trying to get a cron job to run rsync. I started with this:
*/30 * * * * rsync -avz -e "ssh -i /home/ubuntu/ocf_dev_us" ubuntu#10.0.12.76:/home/ubuntu/kumar/ /home/ubuntu/kumar/"
and it wasn't working, so I replaced it with this:
0 * * * * env > /tmp/env.output
and even that isn't working. How do I find out what's going on?
Your cronjob fires only every 60 minutes. Try this
* * * * * env > /tmp/env.output
to find out if your cronjob is working.

Can't make crontab work

I am new to Linux and Ubuntu and I seldom have to use it. I am trying to make this PHP script to run every minute using cron, but firstly I wanted to make some tests.
I created an empty file at /var/www/html/ called test. I ran on terminal:
sudo crontab -e
And added this line:
0 * * * * rm /var/www/html/test
Then saved it and exited. It said "Installing new Crontab"
Nothing happened. Then I created a file bfile.sh that contained:
#!/bin/sh
rm /var/www/html/test
and added the following to crontab:
0 * * * * bash /var/www/html/bfile.sh
Still nothing happened.
What do I have to do to see anything happening from crontab? By the way I checked and the service is running
0 * * * * basically says "run this at 0th minute of every hour."
If you need cron to run your command every minute do * * * * *.
0 * * * * runs once every 1 hour. If you want to run every minute it should be */1 * * * *
You can also check the /var/log/cron file for any errors

crontab not running command

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?
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)
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.

How to sleep 10 seconds before running a linux command?

Simple question: I want to run a cron operation every minute at the 10th second (for example at 2:00:10 PM). The cron operation runs a curl command to download a website page. How can I run a cron operation to do that?
Current crontab setting:
* * * * * curl http://www.google.com/
* * * * * sleep 10;curl http://www.google.com/

Resources