CRONTAB usage

xiaoxiao2021-03-06  47

CRONTAB usage

The file specific location of the crontab command: / var / spool / cron / crontabs directory, each user has its corresponding name, for example, the root user's file is root.

Shanghai Huofe Root users cron is:

00 02 * * 1-5 /usr/sysadm/dailybackup.sh> /uf/logs/dailybackup.log 2> & 1

00 03 * * 1-5 Find / U01 / App / Oracle / Admin / Prod / Archive -Name "* .arc" -mtime 4-EXEC RM {} /;

【Explanation】

The first line means that every week, on Monday to Friday, the system will automatically execute a script DAILYBACKUP.SH, and output the execution information and the error message to the DAILYBACKUP.LOG this file, it is appended form.

The second line means that in the directory / u01 / app / oracle / Admin / PROD / ARCHIVE, find files named * .arc files and delete files 4 days ago.

[Dailybackup.sh]

#! / bin / sh

######################################################################################################################################################################################################################################################################################################## ##################

set_return ()

{

X = $?

IF [$ x -ne 0]; then

Echo "EXIT Code: $ x"

Rval = 1

Fi

}

# Delete At First All Unnecessary Files:

# /uf/sys/res/jcs/reorganize.sh

#

Su - Oracle -c "/u01/app/oracle/product/8.0.6/bin/dbshut"

Su - Oracle -c "/u01/app/oracle/product/8.0.6/bin/lsnrctl stop"

Set_return

/usr/sysadm/backup.sh

# Backupdate = `Date ' % d.% M.% Y'`

// You can generate file names in an annual moon, such as 20040217

# cp /uf/logs/rootsich.log /uf/logs/rootsich.log.

$ Backupdate

# Compress /uf/logs/rootsich.log. ($ssichdat

# Activation of the Unix Copy ORACLE DATABASE PROD TO Train

# Sh /uf/UTIL/Autocopy.sh

Su - Oracle -c "/u01/app/oracle/product/8.0.6/bin/dbstart"

Su - Oracle-C "/u01/app/oracle/product/8.0.6/bin/lsnrctl start"

Set_return

【Explanation】

This script is primarily responsible, first turn off the database, then run the script backup.sh for backup, after the backup is completed, start the database.

[Backup.sh]

#! / bin / sh

######################################################################################################################################################################################################################################################################################################## ##################

# backup.sh

#

######################################################################################################################################################################################################################################################################################################## ##################

FBACKUP -0 -V -N -I / -F / DEV / RMT / 0M> /VAR/adm/fbackupfiles/backup.log 2> & 1

Exit_code = $? EXIT $ EXIT_CODE

【Explanation】

This script is running FBACKUP, making it back up the root directory / all files.

CRONTAB is a timing task trigger under UNIX system, and its user's permissions are recorded in the following two files: /usr/var/adm/cron.deny: The user listed in this file does not allow the crontab command; /usr/var/adm/cron/cron.allow: The user listed in this file allows the crontab command; the format of the crontab command is: crontab -l | -v | -r | -e [username], its parameter meanings Table 1:

parameter name

meaning

-L

Display the content of the user's crontab file

-V

Display the content of the user's crontab file and its submitted time, only for the Compaq series

-r

Remove the user's crontab file from the crontab directory

-e

Edit user's crontab file

The CRONTAB file established by the user is stored in / var / spool / cron / crontabs, and its file name is consistent with the username.

Its format is divided into six sections, the first five sections are time setting segments, and the sixth paragraph is the command segment to be executed.

The format is as follows: * * * *

The meaning of its time period is as follows:

segment

meaning

Ranges

First paragraph

Minute

0-59

Second paragraph

Mean

0-23

Third paragraph

Representative date

1-31

Paragraph 4

Representative month

1-12

Fifth paragraph

Representing the day of the week, 0 represents Sunday

0-6

Example: If the content of the user's crontab file is: 29 19 * * * Echo ITS DINNER TIME, the system is displayed daily 19:29 on the 'ITS DINNER TIME'. Attachment: When this six paragraphs don't have, the program is executed in 1 second. I use the cron when using cron, it is used as a command to execute a command one in each second. This idea misleaded me a long time, in fact, this sentence means that every hour's first minute program is executed once.

转载请注明原文地址:https://www.9cbs.com/read-87469.html

New Post(0)