linux crontab scheduled tasks

 

#Edit the scheduled task file and add the following:

#vi /etc/crontab
0 4 * * 4 root /mnt/schedule.sh >> /mnt/backup_oracle.log

  

#Restart the scheduled task:

#service crond restart

 

The first 5 fields represent:

       Minutes: 0-59

       Hours: 1-23

       Date: 1-31

       Month: 1-12

       Week: 0-6 (0 means Sunday)

 

#Scheduled task script example:

#!/bin/bash
############################################################################################
#
#                           Oracle automic backup script
#
############################################################################################

# 0 4 * * 5 root /mnt/schedule.sh >> /mnt/backup_oracle.log
# define variables
USER=xxxx
PASS=xxxx
SCHEMA=XXXXX


backup_oracle_dump() {
        source /home/oracle/.bash_profile
        current_date=$(date '+%Y%m%d')
        #rm -rf /mnt/dbback/ORACLE_SID_$current_date.dump
        rm -rf /u01/admin/XXX/dpdump/ORACLE_SID_*.dump
        expdp $USER/$PASS@XXX schemas=$SCHEMA dumpfile=ORACLE_SID_$current_date.dump
}


delete_backup_file(){

Folder_A="/mnt/dbback/"
files=$(ls $Folder_A)
old_date=$(date -d last-week +%Y%m%d)

for((i=1;i<8;i++))
do
    echo $i
    echo $old_date
    for file_a in $files
    do
        fname=${file_a:11:8}

        #if [ "$old_date" = "$fname" ]
        #then
        # rm -rf /mnt/dbback/ORACLE_SID_$old_date.dump
        #be
    done
    old_date=$(($old_date-1))
    old_date=$old_date
    bj_date=${old_date:6:2}

    if [ $bj_date = "00" ]
    then
        old_date=$(($old_date-69))
    be
done

}

# __main__
#delete_backup_file
backup_oracle_dump
scp /u01/admin/xxx/dpdump/ORACLE_SID_$current_date.dump [email protected]:/xxx/bak

#num=3
#cur_date=$(date '+%m')
#echo $cur_date
#cur_date = $ (($ cur_date + 0))
#mod_date = $ (($ cur_date% $ num))
#echo $mod_date +"bc"

#if [  $mod_date -eq 1 ]
#then

#   echo $mod_date
 # scp /mnt/dbback/ORACLE_SID_$current_date.dump [email protected]:/xxxx/bak
#be

 

   

   

    Detailed Linux Crontab Scheduled Task Commands

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326450139&siteId=291194637