Wednesday, September 25, 2024

shell script to collect todays cache details of weblogic jvm and send email

 

The following shell script collects today's cache details of weblogic jvm and sends out an email.
The script can ssh to many linux servers and only collect cache details were cache has been created on the present day.

The servers should already have keyless SSH enabled between them

Below is the script

 #!/bin/sh
echo -e "\e[0;36m++++++ \e[0m"
echo -e "\e[0;36m Author : robin.richard@****.com \e[0m"
sleep 5
echo -e "\e[0;36m++++++ \e[0m"
printf "\n ======================= \n Begining cache collection in  PROD  \n ======================= \n"
sleep 4
rm -r report.txt
printf "\n ======================= \n purging old data \n ======================= \n"
echo -e "\e[0;36m++++++ \e[0m"
sleep 5
#rm -r report.txt
for i in oracle@server oracle@server oracle@server oracle@server oracle@server; do ssh $i 'echo  "Server: $(hostname) - Date: $(date)" && find /<path>/servers/*/tmp/_WL_user/ -daystart -ctime 0 -print' >> report.txt; done
sleep 4
printf "\n ======================= \n Completed Cache collection \n ======================= \n"
echo “ prod  cache details” | mail -s “Prod_cache_details” robin.richard@****.com,rramaneedi@****.com,hsinghchouhan@****.com < report.txt
printf "\n ======================= \n Sending Email \n ======================= \n"
echo -e "\e[36;41m++++++ \e[0m"
printf "\n ======================= \n Exiting the system \n ======================= \n"
echo -e "\e[36;41m++++++ \e[0m"

You can also put the script in bash profile as follows
vi ~oracle/.bashrc
alias cachecollector='/home/oracle/cache_collector/robin.sh &'

 

also you can try

for i in oracle@server oracle@server oracle@server oracle@server oracle@server; do ssh $i 'echo  "Server: $(hostname) - Date: $(date)" && echo -e "\e[0;36m++++++ \e[0m" && find /<path>/servers/*/tmp/_WL_user/ -daystart -ctime 0 -print | xargs ls -ltr && echo -e "\e[0;36m++++++ \e[0m"' >> report.txt; done 


or 


for i in oracle@server oracle@server oracle@server oracle@server oracle@server ; do ssh $i 'echo  "Server: $(hostname) - Date: $(date)" && find /<path>/servers/*/tmp/_WL_user/ -daystart -ctime 0 -print' >> report.txt; done


or 


for i in oracle@server oracle@server oracle@server oracle@server oracle@server ; do ssh $i 'echo "********" && echo  "Server: $(hostname) - Date: $(date)" && find /<path>servers/*/tmp/_WL_user/ -daystart -ctime 0 -print && echo "********"' >> report.txt; done


Print index.html from todays date

find /<path>/*/index.html -daystart -ctime 0 -print

Print folders only of todays creation date

find /<path>/*/<path>s/*/tmp/_WL_user/ -mindepth 1 -maxdepth 1 -ctime 0 -print