Automate IP Assignment and CMS Configuration via Bash Script

Create Bash Script to Auto‑Assign IP After Network Change and Configure CMS Automatically

nano update.sh
#!/bin/bash
# Retrieve the server's IP address
NEW_IP_ADDRESS=$(hostname -I | awk '{print $1}')
# Define the path to the configure.php file
CONFIGURE_FILE="/var/www/html/phoenixcart/admin/includes/configure.php"
# Update the IP address in the HTTP_SERVER constant of configure.php file
sed -i "s/const HTTP_SERVER = 'http:\/\/.*';/const HTTP_SERVER = 'http:\/\/$NEW_IP_ADDRESS';/g" $CONFIGURE_FILE
# Update the IP address in the HTTP_CATALOG_SERVER constant of configure.php file
sed -i "s/const HTTP_CATALOG_SERVER = 'http:\/\/.*';/const HTTP_CATALOG_SERVER = 'http:\/\/$NEW_IP_ADDRESS';/g" $CONFIGURE_FILE
# Update the IP address in the domain section of configure.php file
sed -i "s/'domain' => '.*',/'domain' => '$NEW_IP_ADDRESS',/g" $CONFIGURE_FILE
# Output a message indicating the domain has been updated
echo "Domain, HTTP_SERVER, and HTTP_CATALOG_SERVER in configure.php have been updated to $NEW_IP_ADDRESS"
bash update.sh
nano /usr/local/bin/start.sh
#!/bin/bash
cd /home/server
bash update.sh
crontab -e
1
@reboot /usr/local/bin/start.sh

Last updated