Saturday, 18 January 2025

Script to move files to another directory

This script is designed and tested on IBM AIX machine.


#!/bin/ksh
export INSTANCE=$(hostname -s)
export MAILFROM=$INSTANCE'@idhar.udhar.com'
SUBJECT="`hostname` Weblogic old files found in u01 and moved to another directory wllogs"
TO=dbs@idhar.udhar.com

echo "File system usage before moving the files to another directory \n \n" >> /home/oracle/scripts/Filesystem_usage.txt

df -gt /u01 /wllogs >> /home/oracle/scripts/Filesystem_usage.txt

export srcdir=/u01/Oracle/Middleware/Oracle_Home/user_projects/domains/base_domain
setTag=`date '+%d%b%y_%H%M%S_weblogic_oldlogs'`
destdir="/wllogs/CRON_WEBLOGIC_LOGS/$setTag"
export destdir
mkdir $destdir

find $srcdir -name "heapdump.*" -mtime +5 -exec mv {} $destdir \;

sleep 10
echo "File system usage after moving the files to wllogs \n \n" >>/home/oracle/scripts/Filesystem_usage.txt

df -gt /u01 /wllogs >> /home/oracle/scripts/Filesystem_usage.txt
echo "===================="   >>/home/oracle/scripts/Filesystem_usage.txt
cd $destdir

echo "Below files are moved to wllogs from u01 \n \n" >> /home/oracle/scripts/Filesystem_usage.txt
ls -ltr >> /home/oracle/scripts/Filesystem_usage.txt
mailx -s "$SUBJECT" -r "$MAILFROM" $TO < /home/oracle/scripts/Filesystem_usage.txt

No comments:

Post a Comment