1. Write the backup and clear the old log Shell script:
Copy codeThe Code is as follows :#! /Bin/sh
# Backup eoslog
# Author rhao
# Date 2008-12-27
# Define Environment Variables
EOS_HOME =/home/eos
SAS_HOME =/home/eos/SAS
# Test primary and secondary nodes
If test-d '/home/eos/SAS/sasw.web1'
Then
SAS_LOG_HOME = $ SAS_HOME/sasw.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
# Switch the directory to the EOS log file directory
Cd $ SAS_LOG_HOME
# Obtain the current system date
TODAY = 'date + % Y % m % d'
# Backing up the current log
Cp nohup. out $ SAS_LOG_BAK_HOME/$ TODAY. log
# Clearing the current log
Touch nohup. null
Cp nohup. null nohup. out-f
Rm nohup. null
# Clear logs seven days ago
For rmfile in 'Find $ SAS_LOG_BAK_HOME-ctime + 7 ';
Do/bin/rm-rf $ rmfile;
Done
2. Add the script to the crontab of the operating system and directly add VI.
Copy codeThe Code is as follows: [eos @ xcfwbz1 SAS] $ crontab-l
59 23 ***/home/eos/SAS/backup_eoslog.sh
The script is executed at every day.
Shell script for clearing logs
Copy codeThe Code is 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 be root to run this script ."
Exit $ E_NOTROOT
Fi
If [-n "$1"]
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