Ping website url from cronjob apache - cron

I need to setup simple cronejob to ping my website url every 2 minutes, what i did for now make no effect, can somebody help me write simple ping cronjob?
Here is what i have for now
2 * * * * /usr/bin/wget -O - -q -t 1 http://example.com/api/get.php?refresh=yes

This might help:
*/2 * * * * wget -q -O - "http://example.com/api/get.php?refresh=yes" >/dev/null 2>&1
Every 2 minutes (15 in the article), ping the specified file without
any output whatsoever. Just a silent ping to execute my script,
nothing more, nothing less.
Source: https://wp-mix.com/cron-notes-ping-external-url-with-no-output/

Related

Cronjob won't trigger .sh script

I have made this Cronjob that should run some tests. My script works, but cronjob won't trigger it.
Cronjob looks like this:
*/1 * * * * /bin/sh cd ~/Desktop/abc.sh
I want it to run every minute, just for testing purposes.
And my script is:
while read LINE; do curl -o /dev/null --silent --head --write-out "%{http_code} $LINE\n" "$LINE"; done < todo | tee test_results.txt
I can't even find the solution on google or youtube.
If you added #!/bin/bash to your script, then your cronjob should look like:
* * * * * ~/Desktop/abc.sh
Or
* * * * * /home/USER/Desktop/abc.sh
In the first case you have to run cronjob from the same user where of the Desktop folder.

Cron jobs not running in VestaCP (CentOs)

I have written some PHP scripts that I am trying to run with cron jobs in VestaCP, but they don't seem to be running. I have tried to search for other threads on here and on the VestaCP forum that could help me identify the error, but have not found a solution.
Server system:
CentOs 7.4
Vesta 0.9.8-22
I have tested the PHP scripts by going to the links directly. They all work well. But the cron jobs are not running and I can't figure out why.
I have not been able to locate any error messages or logs generated by these cron jobs (even when I remove the "> /dev/null 2>&1"). But I might have been looking in the wrong places.
All of the cron jobs have been added through the VestaCP cron interface.
I have disabled exim, dovecot, clamd, and spamassassin. And I have turned off notifications in the cron panel. Not sure if that is related.
Copied from /var/spool/cron/admin [edited domain name]:
15 02 * * * sudo /usr/local/vesta/bin/v-update-sys-queue disk
10 00 * * * sudo /usr/local/vesta/bin/v-update-sys-queue traffic
30 03 * * * sudo /usr/local/vesta/bin/v-update-sys-queue webstats
*/5 * * * * sudo /usr/local/vesta/bin/v-update-sys-queue backup
10 05 * * * sudo /usr/local/vesta/bin/v-backup-users
20 00 * * * sudo /usr/local/vesta/bin/v-update-user-stats
*/5 * * * * sudo /usr/local/vesta/bin/v-update-sys-rrd
15 6 * * * sudo /usr/local/vesta/bin/v-update-sys-vesta-all
01 4 * * * sudo /usr/local/vesta/bin/v-update-letsencrypt-ssl
*/5 * * * * wget -q -O - "https://testing.example.com/cli/new-projects" > /dev/null 2>&1
*/5 * * * * wget -q -O - "https://example.com/cli/new-projects" > /dev/null 2>&1
30 10 * * * wget -q -O - "https://example.com/cli/project-expiration" > /dev/null 2>&1
*/5 * * * * sudo /usr/local/vesta/bin/v-update-sys-queue letsencrypt
0 10 * * * wget -q -O - "https://testing.example.com/cli/project-expiration" > /dev/null 2>&1
*/2 * * * * wget -q -O - "https://testing.example.com/cli/email-sender" > /dev/null 2>&1
*/2 * * * * wget -q -O - "https://example.com/cli/email-sender" > /dev/null 2>&1
I had the same problem in Ubuntu.
The problem was that the cron jobs created from VestaCP control panel is created for the user and although there is sudo at the beginning of the command, they are not run.
They seem to be called since I can see them on the /tmp/log/syslog file. It does not show any error though. But for some reason, the commands are not executed.
Here are few simple commands to check cron status.
Check if Cron service is running:
pgrep cron
if a number is returned the service is running else not
Check Cron status:
systemctl status cron
Check the current cron file:
crontab -l
Edit cronjob file:
crontab -e
One solution is to create the cron jobs for the root user from the terminal. I have not tried for other users. The cron jobs created for root user will run without a problem.

Cron Jobs Run At Same Time

In my cron job file I have two cronjobs defined:
#Yo1 MAILTO="example#domain.com"
*1****wget -O - -q "http://example.com/cron/test1.php">/dev/null 2>&1
#Yo1 MAILTO="example#domain.com"
*15****wget -O - -q "http://example.com/cron/test2.php">/dev/null 2>&1
The PHP files are simple just sending mails with different subjects.
The issue is that both cronjobs are running on the same time every minute, but as you can see I want them to run on different times. First - every minute, second - every 15 minutes.
Can you help me with this. I can't figure out whats wrong.
Your syntax is incorrect.
Please use the following code
#every minute
* * * * * wget -O - -q "http://example.com/cron/test1.php">/dev/null 2>&1
#every 15 minutes
*/15 * * * * wget -O - -q "http://example.com/cron/test2.php">/dev/null 2>&1
You can use online crontab generators like http://www.crontab-generator.org/
* * * * * wget -O - -q "http://example.com/cron/test1.php">/dev/null 2>&1
15 * * * * wget -O - -q "http://example.com/cron/test2.php">/dev/null 2>&1

How to reboot via cron on scheduled basis. Ubuntu 14.04

I have a very simple script that works from the command line.
#!/bin/bash
reboot
When I put a call to execute the script into root users crontab -e using the following format it does not run. It does run the first two commands, just that last one is giving me grief. I have no MTA installed as I do not need it.
*/10 * * * * service jwtpay restart
0 3 * * * bash /root/backup/mongo.backup.s3.sh kickass /root/backup >/dev/null 2>&1
0 */3 * * * bash /root/reboot.sh >/dev/null 2>&1
What am I missing?
Maybe the script is not executable... Since you use root's crontab why call the binary via a script and not the binary itself? Use the full path to the binary. It may vary on your system. Find out where it is with which reboot.
0 */3 * * * /sbin/reboot
Don't forget to restart the cron daemon, after changeing the crontab.

Status: 301 Moved Permanently ActiveCollab

I tried to set cronjob on my server for ActiveCollab
I use this
*/5 * * * * php "/home/bbb/public_html/tasks/frequently.php" RnuFA > /dev/null
but it always returns error message :
Status: 301 Moved Permanently
Location: https://mywebsite.com/
Content-type: text/html
I've tried to execute the command through SSH and it worked properly.
Can someone help me telling what configuration on my server that need to be checked for this kind of issue?
Thank you
Official recommendation is to use cURL to trigger scheduled tasks, not executable PHP. Currently it is just a recommendation, but upcoming releases will stop shipping /tasks folder so you will have to use cURL.
There are many environments (more than we expected) where there is one PHP that web server uses to prepare the page, and another PHP that runs via command line interface (CLI). This causes all sort of problems, so we decided to use only way way of triggering tasks - via URL.
Bottom line - use cURL. Documentation is here:
https://activecollab.com/help/books/self-hosted-edition/scheduled-tasks-setup.html
Here are sample commands:
*/3 * * * * /usr/bin/curl -s -L "http://url/of/frequently?code=XyZty" > /dev/null
0 * * * * /usr/bin/curl -s -L "http://url/of/hourly?code=XyZty" > /dev/null
0 12 * * * /usr/bin/curl -s -L "http://url/of/daily?code=XyZty" > /dev/null
0 7 * * * /usr/bin/curl -s -L "http://url/of/paper?code=XyZty" > /dev/null
but make sure to check Administration > Scheduled Tasks page of your activeCollab for exact URLs that you need to trigger.

Resources