Skip to content

Instantly share code, notes, and snippets.

@sharang-d
Created August 19, 2019 15:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sharang-d/9d72ce1026afe542afc80f91e9aae55e to your computer and use it in GitHub Desktop.
Save sharang-d/9d72ce1026afe542afc80f91e9aae55e to your computer and use it in GitHub Desktop.
This script connects you to the internet through Cyberoam
Replace NAME with your username and PASS with your password that you use to connect to Cyberoam.
Now add this script to your your crontab like so:
$ crontab -e
Add the following entry:
* * * * * /home/sharang/.shell_scripts/cron_jobs/cyberoam_login.sh
Replace the path with wherever the above mentioned script lies on your system.
The script will be executed every minute. It will check if you are connected to the Internet and if not it will connect you.
It uses the ping command to ping the google DNS server and scrapes the output to calculate the packet loss.
Then it logs you in using the credentials you specified if you are not already connected.
PS. You need to have `curl` installed on your system for this to work.
I was too lazy to check for the existence of it in the script!
#!/bin/bash
packet_loss=`ping -c 1 8.8.8.8 | tail -2 | head -1 | cut -d ' ' -f 6 | sed s/.$//`
if [ $packet_loss -eq 100 ]
then
query_string="mode=191&username=NAME&password=PASS&a=$(date +'%s')&producttype=0"
curl -d "${query_string}" -H "Content-Type:application/x-www-form-urlencoded" http://10.0.0.1:8090/login.xml
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment