Current File : //root/get_hh_details.sh |
# Create a directory for evidence if it doesn't exist
mkdir -p /patch/
filechk="/patch/patch16112023.log"
if [ -f "$filechk" ]
then
echo "Patch 19102020 Already Updated" >> $filechk
exit
fi
touch $filechk
echo "Patch Initiated started" >> $filechk
mkdir -p /patch/evidence/$HOSTNAME
# Search for and organize results into separate files for each log file (including subfolders)
find /var/log -type f -exec grep -l "103\.185\.74\|103\.185\.75\|106\.51\.130\.61" {} + | while read -r logfile; do
grep "103\.185\.74\|103\.185\.75\|106\.51\.130\.61" "$logfile" > "/patch/evidence/$HOSTNAME/$(basename "$logfile")"
done
find /var/sentora/logs -type f -exec grep -l "103\.185\.74\|103\.185\.75\|106\.51\.130\.61" {} + | while read -r logfile; do
grep "103\.185\.74\|103\.185\.75\|106\.51\.130\.61" "$logfile" > "/patch/evidence/$HOSTNAME/$(basename "$logfile")"
done
yum install sshpass -y
# Check if the evidence folder has files
if [ -n "$(find /patch/evidence/$HOSTNAME -type f)" ]; then
# Use sshpass and scp to copy the folder to the remote server
/usr/bin/sshpass -p 'AdminOvi@2023#' scp -o StrictHostKeyChecking=no -r /patch/evidence/$HOSTNAME evidence@103.120.179.70:/home/evidence
rm -frv /patch/evidence/
else
echo "No files found in /patch/evidence/$HOSTNAME. Nothing to copy."
rm -frv /patch/evidence/
fi
echo "Patch completed" >> $filechk