This script automates router restarts on a specified schedule using Selenium WebDriver.
# Update package list
sudo apt update
# Install required packages
sudo apt install -y python3 python3-pip unzip wget curl xvfbpython3 -m venv venv
source venv/bin/activate
pip install -r scripts/requirement.txt# Install Chrome Browser
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo apt install ./google-chrome-stable_current_amd64.deb -y
# Install ChromeDriver (version 136.0.7103.94)
wget https://storage.googleapis.com/chrome-for-testing-public/136.0.7103.94/linux64/chrome-linux64.zip
unzip chrome-linux64.zip
sudo cp chrome-linux64/chrome /usr/local/bin
sudo chmod +x /usr/local/bin/chrome- Create a
.envfile in thescripts/directory:
touch scripts/.env- Add your router credentials and Discord webhook to the
.envfile:
AIRTEL_ROUTER_USERNAME=your_router_username
AIRTEL_ROUTER_PASSWORD=your_router_password
TPLINK_ROUTER_PASSWORD=your_tplink_password
DISCORD_WEBHOOK_URL=your_discord_webhook_url
.env file to version control. It is already included in .gitignore.
python3 scripts/Airtel-Router-reboot.py
python3 scripts/TpLink-Router-reboot.py# Add to System CronJobs
crontab -e
# TpLink Router Restart Automation
0 4 * * * /home/hr/github-repo/Router-Restart-Automation/scripts/venv/bin/python3 /home/hr/github-repo/Router-Restart-Automation/scripts/TpLink-Router-reboot.py >> /home/hr/github-repo/Router-Restart-Automation/scripts/TpLink-Router-reboot.log 2>&1
# Airtel Router Restart Automation
10 4 * * * /home/hr/github-repo/Router-Restart-Automation/scripts/venv/bin/python3 /home/hr/github-repo/Router-Restart-Automation/scripts/Airtel-Router-reboot.py >> /home/hr/github-repo/Router-Restart-Automation/scripts/Airtel-Router-reboot.log 2>&1
# Verify using
crontab -lThe script will generate screenshots at each step for verification in below patten:
1-*.png2-*.png
If any errors occur during execution, the script will:
- Save an error screenshot
- Print an error message
- Close the browser
- Exit with an error status