#!/bin/bash #set -x # Loops through every ~/logs directories for log_path in /home/*/logs do #Gets the name of the home directory home_name=`expr match "$log_path" '/home/\(.*\)/logs'` access_log_to_move=${log_path}/access_log.53.gz error_log_to_move=${log_path}/error_log.53.gz # Last modified date access_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" done exit 0