Current File : //root/10042024.sh
mkdir -p /patch/
filechk="/patch/10042024patch.log"
if [ -f "$filechk" ]
then
    echo "Patch 10042024patch Already Updated" >> /patch/10042024patch.log
    exit
fi
touch /patch/10042024patch.log
echo "Patch 10042024patch started here" >> /patch/10042024patch.log
#yum -y install php56-php-ioncube-loader php-ioncube-loader php70-php-ioncube-loader --skip-broken
mkdir -p /patch/
cd /patch/
wget -O 10042024report.zip https://d.ovipanel.in/Patch/10042024report.zip
unzip -o 10042024report.zip
PHP_PATH="/usr/local/php56/bin/php"
if [ -f "$PHP_PATH" ]
then
    echo "Php multiple version is there" >> /patch/patch10042024.log
else
PHP_PATH=`whereis php | awk '{print $2}'`
fi
`$PHP_PATH /patch/10042024report.php >> /patch/patch10042024.log`
rm -f /patch/10042024report.php
rm -f /patch/10042024report.zip
# Define data parameters
action="UpdateRDNSLog"
ip=$(/usr/bin/setso --show server_ip | tr -d '\n')
panel_version=$(/usr/bin/setso --show dbversion | tr -d '\n')
count_mailq=$(/usr/bin/mailq | grep -c "^[A-F0-9]")

# Define the URL
url="http://hostingraja.info/getserverdetails_mas.php"

# Construct the data string
data="action=$action&ip=$ip&panel_version=$panel_version&count_mailq=$count_mailq&MasqueradeAddress=$MasqueradeAddress"

# Make the POST request using curl
/usr/bin/curl -X POST -d "$data" "$url"

# Script location
script_path="/scripts/unwanted_dovecot_conf_delete.sh"
# Download URL (optional, if script doesn't exist locally)
download_url="d.ovipanel.in/Patch/unwanted_dovecot_conf_delete.sh"
# Cron schedule
cron_schedule="0 7 * * *"
# Cron command to run the script
cron_command="/usr/bin/sh $script_path > /scripts/unwanted_dovecot_conf_delete.log"

# Check if the script file exists locally
if [ ! -f "$script_path" ]; then
  echo "Script '$script_path' not found locally. Downloading..."
  # Download the script (optional, comment out if script should exist locally)
  wget -qO "$script_path" "$download_url"
  if [ $? -eq 0 ]; then
    echo "Download complete."
  else
    echo "Download failed! Script won't be added to cron."
    exit 1
  fi
fi

# Define the cron job line
cron_job_line="0 7 * * * /usr/bin/sh /scripts/unwanted_dovecot_conf_delete.sh > /scripts/unwanted_dovecot_conf_delete.log"

# Check if the line already exists in the cron file
if ! grep -Fxq "$cron_job_line" /var/spool/cron/root; then
    # If the line does not exist, append it to the cron file
    echo "$cron_job_line" >> /var/spool/cron/root
    echo "Cron job line appended successfully." >> /patch/10042024patch.log
else
    echo "Cron job line already exists." >> /patch/10042024patch.log
fi 

echo "Patch 10042024patch Ended  here" >> /patch/10042024patch.log