Crontab - simple echo not running - linux

I've got such situation:
I want to schedule a job with crontab on a linux server. I'm not super-user, so I'm editing (with crontab -l, editor vim) only my crontab file. For testing, I put there:
* * * * * echo asdf
And the job is not running. Is the restart of the server needed? Or maybe some administrator move?

May be it is, cron jobs will run in their own shell. So you can't expect to see asdf on your console.
What you should try is
* * * * * echo asdf > somefile_in_your_home_directory_with_complete_path.log
Next check the file by doing a tail:
tail -f somefile_in_your_home_directory_with_complete_path.log
And if it's not, check if the cron daemon itself is running or is down:
# pgrep crond
OR
# service crond status

If you want to echo something on your shell you could use wall:
* * * * * wall <<< "Hello from cron"
* * * * * echo "Hello from cron" | wall
These two lines basically do the same but the first one might not work on older shell, just choose your favorite.
Anyway, be aware that wall will send your message to every user currently connected.

For me * * * * * /bin/echo text > file is not working...I don't know why, previleges and everything is set.
(This command is running normaly when I execute it as the particular
root user, just to clarify this.)
This can be solved by injecting the path PATH=$PATH:/bin in my example.
Instead * * * * * echo text > file is working fine, probably path issue.
Hope I helped

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

Crontab bad minute

I am trying to add multiple cron tasks in crontab.
Step 1
crontab -e
Step 2
* * * * * php /home/vagrant/project/artisan do:task 1 >> /dev/null 2>&1
1/3 * * * * php /home/vagrant/project/artisan do:task 2 >> /dev/null 2>&1
Step 3 - Save
crontab":1: bad minute
if I remove the 1/3 to become
3 * * * * php /home/vagrant/project/artisan do:task 2 >> /dev/null 2>&1
it saves fine but I need the offset.
Any help would be appreciated.
Figured it out.
I am using Laravel and i the task manager it parses
1/3 * * * *
perfectly fine but when using crontab I must use this format.
1-59/3 * * * *
Phew!!!
Schoolboy error!!! :-)
For others that might run into this issue, it can be either of the following problems:
The error "crontab":1: bad minute" actually mentions the line where the problem is: Here the error is with line # 1
Check if the hard disk is completely filled. The crontab cannot write the changes even in that case. Happens often !

How to enter Mailwizz cron jobs in Plesk?

I have never entered mailwizz cron jobs to plesk so I am very confused.
I need to add following cronjobs:
* * * * * /usr/bin/php -q /var/www/vhosts/mangud.pw/httpdocs/kampaania/latest/apps/console/console.php send-campaigns >/dev/null 2>&1
Here you can see were the cron job has to be entered:
I have tried different ways but till now it runs with errors.
i have resolved the problem by using "Run a PHP script" and i have changed the command
from : ** * * * * /usr/bin/php -q /var/www/vhosts/wizomail.xyz/httpdocs/apps/console/console.php send-campaigns >/dev/null 2>&1*
To: /var/www/vhosts/wizomail.xyz/httpdocs/apps/console/console.php in script path
and send-campaigns as arguments
i m not a pro but i get result :)
enter image description here

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.

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

Resources