Running aide --check as a crontab job once a week - linux

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

Related

Cannot make CRON work for user on CentOS 7

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

AWS Linux crontab job isnt executing script

First of all I've tried multiple solutions I know there are several posts with similar problems none of those were a solution for me.
I have a Clojure application which is started using:
lein run -m tsdb-delete.core
The plan is to execute this every day at midnight I want to avoid using Clojure based cron libraries and this is a very light weight application.
I created the following script (start.sh):
/usr/bin/lein run -m tsdb-delete.core
which calls this script at run time (delete.sh):
#!/bin/bash
echo "Deleting:" $1
OUTPUT="$(sudo /opt/opentsdb/build/tsdb scan --delete 30d-ago 7d-ago sum $1)"
echo "${OUTPUT}"
If I call './start.sh' manually it all works as expected and I see console output.
start.sh is located at /home/ec2-user/tsdb-delete/start.sh and delete.sh is located at /home/ec2-user/tsdb-delete/delete.sh
I have added the following to me crontab using crontab -e
PATH=/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/ec2-user/bin
SHELL=/bin/bash
*/5 * * * * /home/ec2-user/tsdb-delete/start.sh > /var/tmp/tsdb-delete.out
* * * * * env > /tmp/env.output
* * * * * env > /tmp/env.output is used for debugging purposes, the contents of env.output are as follows:
SHELL=/bin/bash
USER=ec2-user
PATH=/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/ec2-user/bin
PWD=/home/ec2-user
LANG=en_GB.UTF-8
SHLVL=1
HOME=/home/ec2-user
LOGNAME=ec2-user
_=/bin/env
and if I run env in the terminal myself I get the following:
HOSTNAME=ip-xx-xx-xx-xx
LESS_TERMCAP_md=
LESS_TERMCAP_me=
TERM=xterm-256color
SHELL=/bin/bash
HISTSIZE=1000
SSH_CLIENT=xxxxxxxxx
LESS_TERMCAP_ue=
SSH_TTY=/dev/pts/0
USER=ec2-user
LS_COLORS=rs=0:di=38;5;27:ln=38;5;51:mh=44;38;5;15:pi=40;38;5;11:so=38;5;13:do=38;5;5:bd=48;5;232;38;5;11:cd=48;5;232;38;5;3:or=48;5;232;38;5;9:mi=05;48;5;232;38;5;15:su=48;5;196;38;5;15:sg=48;5;11;38;5;16:ca=48;5;196;38;5;226:tw=48;5;10;38;5;16:ow=48;5;10;38;5;21:st=48;5;21;38;5;15:ex=38;5;34:*.tar=38;5;9:*.tgz=38;5;9:*.arc=38;5;9:*.arj=38;5;9:*.taz=38;5;9:*.lha=38;5;9:*.lzh=38;5;9:*.lzma=38;5;9:*.tlz=38;5;9:*.txz=38;5;9:*.tzo=38;5;9:*.t7z=38;5;9:*.zip=38;5;9:*.z=38;5;9:*.Z=38;5;9:*.dz=38;5;9:*.gz=38;5;9:*.lrz=38;5;9:*.lz=38;5;9:*.lzo=38;5;9:*.xz=38;5;9:*.bz2=38;5;9:*.bz=38;5;9:*.tbz=38;5;9:*.tbz2=38;5;9:*.tz=38;5;9:*.deb=38;5;9:*.rpm=38;5;9:*.jar=38;5;9:*.war=38;5;9:*.ear=38;5;9:*.sar=38;5;9:*.rar=38;5;9:*.alz=38;5;9:*.ace=38;5;9:*.zoo=38;5;9:*.cpio=38;5;9:*.7z=38;5;9:*.rz=38;5;9:*.cab=38;5;9:*.jpg=38;5;13:*.jpeg=38;5;13:*.gif=38;5;13:*.bmp=38;5;13:*.pbm=38;5;13:*.pgm=38;5;13:*.ppm=38;5;13:*.tga=38;5;13:*.xbm=38;5;13:*.xpm=38;5;13:*.tif=38;5;13:*.tiff=38;5;13:*.png=38;5;13:*.svg=38;5;13:*.svgz=38;5;13:*.mng=38;5;13:*.pcx=38;5;13:*.mov=38;5;13:*.mpg=38;5;13:*.mpeg=38;5;13:*.m2v=38;5;13:*.mkv=38;5;13:*.ogm=38;5;13:*.mp4=38;5;13:*.m4v=38;5;13:*.mp4v=38;5;13:*.vob=38;5;13:*.qt=38;5;13:*.nuv=38;5;13:*.wmv=38;5;13:*.asf=38;5;13:*.rm=38;5;13:*.rmvb=38;5;13:*.flc=38;5;13:*.avi=38;5;13:*.fli=38;5;13:*.flv=38;5;13:*.gl=38;5;13:*.dl=38;5;13:*.xcf=38;5;13:*.xwd=38;5;13:*.yuv=38;5;13:*.cgm=38;5;13:*.emf=38;5;13:*.axv=38;5;13:*.anx=38;5;13:*.ogv=38;5;13:*.ogx=38;5;13:*.aac=38;5;45:*.au=38;5;45:*.flac=38;5;45:*.mid=38;5;45:*.midi=38;5;45:*.mka=38;5;45:*.mp3=38;5;45:*.mpc=38;5;45:*.ogg=38;5;45:*.ra=38;5;45:*.wav=38;5;45:*.axa=38;5;45:*.oga=38;5;45:*.spx=38;5;45:*.xspf=38;5;45:
LESS_TERMCAP_us=
MAIL=/var/spool/mail/ec2-user
PATH=/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/ec2-user/bin
PWD=/var/tmp
LANG=en_GB.UTF-8
HISTCONTROL=ignoredups
SHLVL=1
HOME=/home/ec2-user
LOGNAME=ec2-user
SSH_CONNECTION= xxxxxxx
LESSOPEN=||/usr/bin/lesspipe.sh %s
LESS_TERMCAP_se=
_=/bin/env
OLDPWD=/home/ec2-user
The key environment attributes seem to match, and in var/cron/log I see the following:
Oct 28 11:45:01 ip-xx-xx-xx-xx CROND[23591]: (ec2-user) CMD (/home/ec2-user/tsdb-delete/start.sh > /var/tmp/tsdb-delete.out)
Oct 28 11:45:01 ip-xx-xx-xx-xx CROND[23592]: (ec2-user) CMD (env > /tmp/env.output)
and in /var/spool/mail/ I don't see any error messages being thrown and the file /var/tmp/tsdb-delete.out is not created.
Any ideas?
sudo requires a tty, which doesn't exist while running a cron. (1,2)
Here's a better solution; place this in /etc/cron.d/tsdb-delete:
*/5 * * * * root /home/ec2-user/tsdb-delete/start.sh > /var/tmp/tsdb-delete.out
This requires having the execute bit set on start.sh. Also note the /etc/cron entries take a sixth argument which is the user.
It's also bad form to use something like sudo in a cron, and generally using a user cron (crontab -e) is not terribly friendly for configuration management. The above fixes these problems. Still, I'd recommend moving the script to a safer location (since it's running via root), and since it's root you can easily send output to /var/log/ (and append it):
*/5 * * * * root /opt/tsdb-delete/start.sh >> /var/log/tsdb-delete.out

Shell script runs manually but not executed through cron job

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?

Cronjob failing on Debian

I'm having no idea why my cronjob isn't executed. Here are the details:
I've a script inside /usr/src named stundenplan.sh, which executes a jar file.
The script itself works if you are running it from the console.
But trying to run it from a cronjob it doesn't work.
The script looks like this:
#!/bin/sh
java -jar vorlesungsplaene.jar
The jar file lies in the same directory as expected.
I defined two cronjobs:
# m h dom mon dow command
30 * * * * /usr/src/stundenplan.sh
0-59 * * * * echo "dude" >> /tmp/test.txt
The job below works fine, writing "dude" meticulously in the test.txt file.
As you can see in the syslog, the job above fails:
Jul 18 15:29:01 vps47327 /USR/SBIN/CRON[16361]: (root) CMD (echo "dude" >> /tmp/test.txt)
Jul 18 15:30:01 vps47327 /USR/SBIN/CRON[16364]: (root) CMD (/usr/src/stundenplan.sh)
Jul 18 15:30:01 vps47327 /USR/SBIN/CRON[16365]: (root) CMD (echo "dude" >> /tmp/test.txt)
Jul 18 15:30:01 vps47327 /USR/SBIN/CRON[16363]: (CRON) error (grandchild #16364 failed with exit status 1)
Any suggestions, ideas or solutions? ;)
It looks like a path issue. Crontab is probably being run from some arbitrary directory so it can't find the jar file.
Try doing:
30 * * * * cd /usr/src && ./stundenplan.sh
That's not really the prettiest way to go about it, but if it works, then at least you know what the problem is. Possibly it might be more elegant to put the full path of the jar file in the script then, but I'll leave that question to you. :)
Hope it helps!

Cron Job in Fedora 8 - Not getting the desired result

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

Resources