#!/bin/bash#set -x# Loops through every ~/logs directoriesfor log_path in /home/*/logsdo#Gets the name of the home directoryhome_name=`expr match "$log_path" '/home/\(.*\)/logs'`access_log_to_move=${log_path}/access_log.53.gzerror_log_to_move=${log_path}/error_log.53.gz# Last modified dateaccess_date_stamp=$(stat 2>&- $access_log_to_move -c '%y' | awk -F' ' '{print $1}')error_date_stamp=$(stat 2>&- $error_log_to_move -c '%y' | awk -F' ' '{print $1}')#mkdir ${log_path}/../log_archive/# Filenames are in the following format:- imagine2_access_log_2004-10-20.gz cp 2>&- $access_log_to_move "${log_path}/../log_archive/${home_name}_access_log_$access_date_stamp.gz"cp 2>&- $error_log_to_move "${log_path}/../log_archive/${home_name}_error_log_$error_date_stamp.gz"doneexit 0