On: summary of common symbols for Linux cron planning tasks

Time:2021-12-3

 [[email protected] ~]# crontab –help
crontab: invalid option — ‘-‘
crontab: usage error: unrecognized option
usage: crontab [-u user] file
crontab [-u user] [ -e | -l | -r ]
(default operation is replace, per 1003.2)
-E (edit user’s crontab) edit crontab work content
-L (list user’s crontab) to view the work content of crontab
-R (delete user’s crontab) deletes all crontab tasks
-i (prompt before deleting user’s crontab)
-s (selinux context)

By default, any user who is not listed in / etc / cron.deny can execute “crontab – e” to edit his own routine commands,

The meaning of representation

minute

hour

date

month

week

Digital range

0-59

0-23

1-31

1-12

0-7

When the number of weeks is 0-7, it means “Sunday”,

Auxiliary character

Special characters

Representative meaning

*(asterisk)

It means to accept at any time,

, (comma)

Represents a split time period. If you want to execute 2:00 and 4:00,

0 2,4 * * * command

There are five columns of time parameters. The second column is 2, and 4 represents 2:00 and 4:00

-(minus sign)

Represents the range of a period of time, for example, every 10 minutes between 7:00 and 10:00

Work: 10 7-10 * * command

The second column becomes 7-10 for 7 8 9 10

/N (slash)

That n stands for number, which means every n unit interval, for example, every 5 minutes,

Then: * / 5 * * command

It can also be written as 0-59 / 5, which means the same

System task plan

[[email protected] ~]# cat /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
# For details see man 4 crontabs
# Example of job definition:
# .—————- minute (0 – 59)
# | .————- hour (0 – 23)
# | | .———- day of month (1 – 31)
# | | | .——- month (1 – 12) OR jan,feb,mar,apr …
# | | | | .—- day of week (0 – 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed

Crontab -e is designed for users’ crons.

Basically, the minimum detection limit of cron service is “minutes”, so cron reads the data contents in / etc / crontab and / var / spool / cron every minute.

Standard output (stout): Code 1 uses > or > >

Standard error output (stderr): Code 2 uses 2 > or 2 > >

Black hole / dev / null

Error output 2 > & 1

Cron lets scheduled tasks not output on the screen using > / dev / null 2 > & 1

[[email protected] ~]# crontab -l
*/1 * * * * echo “hello” >> /tmp/test.txt
[[email protected] ~]# cat /tmp/test.txt
hello
[[email protected] ~]# cat /tmp/test.txt
hello
hello

Let the output go into the black hole

[[email protected] ~]# crontab -l
*/1 * * * * echo “hello”
[[email protected] ~]# crontab -l
*/1 * * * * echo “hello” > / dev / null 2 > & 1 is output to the black hole

For other help, see man    cron   Or man   crontab

PS: ocsng Linux client installation

aptitude -y install gcc automake autoconf libtool make
aptitude -y install dmidecode libxml-simple-perl libcompress-zlib-perl libnet-ip-perl libwww-perl libdigest-md5-perl libnet-ssleay-perl
aptitude -y install libcrypt-ssleay-perl libnet-snmp-perl libproc-pid-file-perl libproc-daemon-perl net-tools libsys-syslog-perl pciutils smartmontools read-edid nmap
tar –xvzf Ocsinventory-Agent-2.0.x.tar.gz
cd Ocsinventory-Agent-2.0.x
env PERL_AUTOINSTALL=1 perl Makefile.PL
make
make install