First, write backup and clear old log shell script:
Copy Code code as follows:
#!/bin/sh
#backup Eoslog
#author Rhao
#date 2008-12-27
#定义环境变量
Eos_home=/home/eos
Sas_home=/home/eos/sas
# Test primary and secondary nodes.
If test-d '/home/eos/sas/sas1_web1 '
Then
Sas_log_home= $SAS _home/sas1_web1/sas_domain/bin
Else
Sas_log_home= $SAS _home/sas2_web1/sas_domain/bin
Fi
# define and create a log backup directory
Sas_log_bak_home= $EOS _home/saslog/
Mkdir-p $SAS _log_bak_home
# Toggle Directory to EOS log file directory
CD $SAS _log_home
# Get current system date
today= ' Date +%y%m%d '
# Back up the current log
CP nohup.out $SAS _log_bak_home/$TODAY. LOG
# Clear Current Log
Touch Nohup.null
CP Nohup.null Nohup.out-f
RM nohup.null
# clear seven days before the log
For Rmfile in ' Find $SAS _log_bak_home-ctime +7 ';
DO/BIN/RM-RF $rmfile;
Done
Second, the script into the operating system of the crontab, direct VI to join CAN
Copy Code code as follows:
[Eos@xcfwbz1 sas]$ Crontab-l
* * */home/eos/sas/backup_eoslog.sh
It says the script is executed 23:59 every day.
Clear log (logfile) shell script
Copy Code code as follows:
#!/bin/bash
Log_dir=/var/log
Root_uid=0
Lines=50
e_xcd=66
e_notroot=67
If ["$UID"-ne "$ROOT _uid"]
Then
echo "must is root to run this script."
Exit $E _notroot
Fi
If [-N ' $]
Then
Lines=$1
Else
lines= $LINES
Fi
CD $LOG _dir
If [' pwd '!= "$LOG _dir"]
Then
echo "Can" t change to $LOG _dir. "
Exit $E _xcd
Fi
tail-$lines Messages > Mesg.temp
MV Mesg.temp messages
echo "Logs cleaned up."
Exit 0