OS : Fedora release 8
user : root
crontab -e :output
11 * * * * root /bin/touch /home/arun/Desktop/f1
But this cron job is not creating new file 'f1'.
/var/log/cron :says
Feb 21 09:11:01 localhost CROND[5762]: (root) CMD (root /bin/touch /home/arun/Desktop/f1 )
In command line I executed below command and it creates file f1.
#/bin/touch /home/arun/Desktop/f1
You are trying to execute the command root /bin/touch /home/arun/Desktop/f1
The executable 'root' obviously does not exist. Try removing 'root' (via crontab -e) and make the crontab entry look like:
11 * * * * /bin/touch /home/arun/Desktop/f1
Related
I'm having real problems getting a simple (aide --check) job to run as a crontab job. I've tried everything I can think of but it won't seem to run. I've tried specifying the shell in crontab:
SHELL=/bin/bash
I've tried all kinds of variations of the command line:
*/1 * * * * root /bin/bash /usr/sbin/aide --check
*/1 * * * * /bin/bash /usr/sbin/aide --check
*/1 * * * * root /usr/sbin/aide --check
*/1 * * * * root /bin/bash /usr/sbin/aide --check >> /var/log/SystemFileCheck.log
Plus others but just can't get it to run. I've followed online guides which all say I'm doing it correctly. I've tried putting it into a bash script instead and running that but no luck. What am I doing wrong?
These are some of the errors I'm getting:
Mar 30 11:25:01 localhost CROND[14060]: (root) CMD (root /bin/bash /usr/sbin/aide --check >> /var/log/SystemFileCheck.log)
Mar 30 11:25:01 localhost CROND[14058]: (root) CMDOUT (/bin/sh: root: command not found)
Mar 30 11:28:01 localhost CROND[14397]: (root) CMD (root /bin/SystemIntegCheck.sh >> /var/log/SystemFileCheck.log)
Mar 30 11:28:01 localhost CROND[14395]: (root) CMDOUT (/bin/bash: root: command not found)
Mar 30 11:39:01 localhost CROND[16094]: (root) CMD (/bin/bash /usr/sbin/aide --check)
Mar 30 11:39:01 localhost CROND[16092]: (root) CMDOUT (/usr/sbin/aide: /usr/sbin/aide: cannot execute binary file)
Can anyone shed some light on this?
Thanks in advance
PS. the once a minute is just for testing
A user id can only be specified in the system crontab file. The entries of a user's crontab file don't take a user id. The entries in question are apparently found in a user's crontab file, which is why you get root: command not found from the first, third and fourth entries.
From the second, you get cannot execute binary file because you ask bash to execute /usr/sbin/aide as a bash script when it's not a bash script. You should be using
*/1 * * * * /usr/sbin/aide --check
This is file /var/spool/cron/[USER]:
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
0 */2 * * * /usr/bin/wget -O - http://[WEBSITE]/[STUFF] >/dev/null 2>&1
I made this CRON to visit website every second hour. But it is not working, because when I type command about CRON status, then it says this:
$ systemctl status crond
● crond.service - Command Scheduler
Loaded: loaded ...
Active: active (running) ...
...
crond[6967]: (CRON) bad minute (/var/spool/cron/[USER])
...
It is weird, because when I move it to the /var/spool/cron/root, then it works. This "bad minute" shows only for other users. But why?
CHMOD is 600 and owner is the user I talk about.
I think you shouldn't edit the cron file directly, have you tried editing it when logged in to the correct user with this command:
crontab -e
Also check that your /etc/crontab file is correct
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly
I am trying to schedule a job using cron.
Following are the steps that i did:
sudo vi /etc/crontab
Added the following line :
* * * * * root /bin/ls >> corn_example
Still job is not getting triggered.
I suspect it's because you're not specifying the folder to 'ls' or a folder location for the example file to be create in.
I'd try:
* * * * * root /bin/ls /tmp/ >> /tmp/corn_example
I have problem with crontab because my crontab entry not running
$ date
Tue Jan 6 07:21:11
$ crontab -l
*/2 6-11 * * 1-3 hostnamectl >> /home/bob/hostsname.txt
this crontab should be running every 2 minutes from 6-11 AM every monday - weds, but nothing happened. record in /var/log/cron for this cronjobs is empty
i debug to ensure crond is running and change to below
* * * * * hostnamectl >> /home/bob/hostsname_debug.txt
cronjobs running as expected every 1 minutes. i see hostsname_debug.txt in home directory.
i see the log in /var/log/cron
why the first cronjobs not running?
I am using a shell script to delete log files in my Linux machine. And I have used crontab to execute this job periodically. I can execute this script manually and see it is working fine. But the script is not triggered through cron job.
Shell script:
[root#testVM-dev log]# vim /path_to_dir/log_cleanup.sh
#!/bin/bash
now=$(date)
echo "Cron Job to delete log files start...# $now" | tee -a /path_to_dir/log/cronjob_log.log
/usr/bin/find /path_to_dir/log/localhost_access_log.* -type f -mtime +5 -print -delete | tee -a /path_to_dir/log/cronjob_log.log
echo "Delete files completed!" | tee -a /path_to_dir/log/cronjob_log.log
crontab entry: (Runs every minute)
[root#testVM-dev log]# crontab -l
*/1 * * * * root /path_to_dir/log_cleanup.sh
Also I have checked in cron logs that the job is executed every minute. But I couldn't see any logs in the targeted log file "cronjob_log.log"
cron logs:
vim /var/log/cron
Jul 16 03:56:01 rstestVM-dev crond[19131]: (root) CMD (root /path_to_dir/log_cleanup.sh)
Jul 16 03:57:01 rstestVM-dev crond[19150]: (root) CMD (root /path_to_dir/log_cleanup.sh)
Jul 16 03:58:01 rstestVM-dev crond[19168]: (root) CMD (root /path_to_dir/log_cleanup.sh)
Jul 16 03:59:01 rstestVM-dev crond[19188]: (root) CMD (root /path_to_dir/log_cleanup.sh)
Can someone help me on what is going wrong here?
Besides manually specifying value of PATH, try specifying the path to tee and date.
/usr/bin/date, /usr/bin/tee
I have found the solution. That I have removed the user from crontab entry & it worked.
Original crontab entry:
[root#testVM-dev log]# crontab -l
*/1 * * * * root /path_to_dir/log_cleanup.sh
After modification:
[root#testVM-dev log]# crontab -l
*/1 * * * * /path_to_dir/log_cleanup.sh
Now I got confused why the user entry in cron job didn't work? Can someone explain?