How to add a cron job with crontab -e - cron

My system is centos 7.4.
After crontab -e,I add
MAILTO=root
30 4 * * * root /usr/sbin/aide --check
Then I receive email as below:
From: "(Cron Daemon)" <root#mail.mydomain.com>
To: root#mail.mydomain.com
Subject: Cron <root#myserver> root /usr/sbin/aide --check
Content-Type: text/plain; charset=UTF-8
Auto-Submitted: auto-generated
Precedence: bulk
X-Cron-Env: <XDG_SESSION_ID=37>
X-Cron-Env: <XDG_RUNTIME_DIR=/run/user/0>
X-Cron-Env: <LANG=en_US.UTF-8>
X-Cron-Env: <MAILTO=root>
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/root>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=root>
X-Cron-Env: <USER=root>
Message-Id: <20190300432001.5EC7524C51#mail.mydomain.com>
Date: Fri, 1 Mar 2019 04:32:01
/bin/sh: root: command not found
I checked /var/log/aide/aide.log is empty, there's no any information in messages and secure.It seemed my crontab script is somewhere wrong.
I just want to receive aide --check report,where is the problem?

The command you must exec is this:
MAILTO=root
30 4 * * * /usr/sbin/aide --check
Cron interpret root as command. The original cron records differ from those in cron.daily and so on directories because the standard cron records are per user, not per specific time

Related

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

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

Why is my crontab not working when I use local time in RedHat?

I defined a cron job to refer to my local time but it is not working.
I have tried to define it using Universal time. It is working, but my question is why the crontab is not working on my local time.
See the definition details below.
Is there something that needs to be changed to make crontab use the local time?
[root#mykultestrhel04t hoho]# timedatectl
Local time: Mon 2019-08-26 14:33:22 +08 >> not working
Universal time: Mon 2019-08-26 06:33:22 UTC >> working
RTC time: Mon 2019-08-26 06:33:22
An example crontab entry would be
09 06 * * * /usr/bin/find /test/hoho -mtime +60 -exec rm -f {} \;
The time refers to UTC, not my local time.
Can anyone help?

Crontab Job not Executing

System Date:
Wed Nov 22 02:14:54 UTC 2017
CronJob (save environment variables to file in /tmp)
02 12 * * * env > /tmp/env.txt
This job did not execute between at 02:12:00 - 02:13:00 despite being initialized at 02:10:00
The command env > /tmp/env.txt executes just fine when I do it outside of crontab. Can anyone tell me what I'm doing wrong?
You've reversed hours and minutes in your crontab file.
This should fix your problem:
12 02 * * * env > /tmp/env.txt

Sqlplus command not found when running from crontab

This is the case, I made 3 files to execute backup database command in rman
test.sh:
#!/bin/bash
sqlplus /nolog #/u01/conectar.sql
conectar.sql:
connect sys/manager as sysdba
ho rman target mydatabase/mypassword #/u01/backup.sh
backup.sh:
#!/bin/bash
RUN {backup database;}
and then I did all the chmod u+x for the files to make them executable, then export EDITOR=nano to change the cron editor.
when I go to crontab -e i put
00 15 * * * /u01/test.sh
If I clic this test.sh manually, the operation runs normally, but then in the crontab I get the "you got a mail" thing with this message
From root#localhost.localdomain Thu Dec 22 16:20:01 2016
Return-Path:
X-Original-To: oracle
Delivered-To: oracle#localhost.localdomain
Received: by localhost.localdomain (Postfix, from userid 500)
id 956CD41D4B; Thu, 22 Dec 2016 16:20:01 -0400 (AST)
From: root#localhost.localdomain (Cron Daemon)
To: oracle#localhost.localdomain
Subject: Cron /u01/test.sh
Content-Type: text/plain; charset=UTF-8
Auto-Submitted: auto-generated
X-Cron-Env:
X-Cron-Env:
X-Cron-Env:
X-Cron-Env:
X-Cron-Env:
Message-Id: <20161222202001.956CD41D4B#localhost.localdomain>
Date: Thu, 22 Dec 2016 16:20:01 -0400 (AST)
/u01/test.sh: line 3: sqlplus: command not found"
Please can you remake the script or the crontab for me? If you can answer with the exactly modifications I would appreciate it, I'm not an expert in this environment so a general knowledge needed answer will leave me the same, thanks.
You can do it in many ways:
Just before the cron line:
PATH=$PATH:/full/path/to/oracle/bin
Or on the cron line itself:
00 15 * * * PATH=$PATH:/full/path/to/oracle/bin /u01/test.sh
Let your script test.sh source another shared script that sets up your Oracle environment:
source /path/to/oracle_env.sh
I prefer the third method because it is very flexible and it helps us keep the crontab uncluttered. .bash_profile should be meant for interactive shell only - it is not good to share it with scheduled scripts, especially in production.

Trying to schedule first cron job, does this schedule look good

I'm trying to schedule my first cron job:
* 0830 * * 1,3,5,0 ls -l
I'm expecting the job to run Mon, Wed, Fri, and Sun at 8:30am
It's
30 8 * * 0,1,3,5 ls -l
First the minutes, then hours; allways seperated by a whitespace

Resources