curl -s 'https://gist.githubusercontent.com/ali-essam/7ab5768370a701142cc936e597e8ed48/raw/1c691fcbdd37f818fe7538bb40a4f21c9a2a3631/install' | sudo bash
Last active
October 3, 2016 09:41
Star
You must be signed in to star a gist
Get Vodafone EG USB quota and notify user
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl 'https://gist.githubusercontent.com/ali-essam/7ab5768370a701142cc936e597e8ed48/raw/8f2e50f2f43061135fe65dc857ced39a275cca49/vodafonequota' | sudo tee /etc/network/if-up.d/vodafonequota > /dev/null | |
sudo chmod +x /etc/network/if-up.d/vodafonequota | |
echo "Vodafone Quota Notifier Setup Successfully" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# CLI Version | |
INTERFACE=enx00a0c6000000 | |
IFACE="$INTERFACE" | |
function notifyquota { | |
PAGE=$(curl -s 'http://www.vodafone.com.eg/data/enterpriseUsbRemainingData.do?lang=en' | grep input) | |
CONSUMED_QUOTA=$(echo "$PAGE" | grep consumedQuota | grep -oE "[0-9]+\.[0-9]*") | |
MAIN_QUOTA=$(echo "$PAGE" | grep mainQuota | grep -oE "[0-9]+\.[0-9]*") | |
TITLE="Vodafone USB" | |
MESSAGE="Quota used $CONSUMED_QUOTA MBs of $MAIN_QUOTA MBs" | |
echo "$TITLE" | |
echo "$MESSAGE" | |
} | |
if [ "$IFACE"=="$INTERFACE" ] | |
then | |
echo "Connecting..." | |
notifyquota | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
INTERFACE=enx00a0c6000000 | |
if [ "$ADDRFAM" != inet ]; then | |
exit 0 | |
fi | |
if [ "$IFACE" != "$INTERFACE" ]; then | |
exit 0 | |
fi | |
function notifyquota { | |
PAGE=$(curl -s 'http://www.vodafone.com.eg/data/enterpriseUsbRemainingData.do?lang=en' | grep input) | |
CONSUMED_QUOTA=$(echo "$PAGE" | grep consumedQuota | grep -oE "[0-9]+\.[0-9]*") | |
MAIN_QUOTA=$(echo "$PAGE" | grep mainQuota | grep -oE "[0-9]+\.[0-9]*") | |
TITLE="Vodafone USB" | |
MESSAGE="Quota used $CONSUMED_QUOTA Mbs of $MAIN_QUOTA Mbs" | |
# TODO: Separate in different function | |
USER=$(who | awk 'NR==1{print $1}') | |
USER_DBUS_PROCESS_NAME="gconfd-2" | |
NOTIFY_SEND_BIN="/usr/bin/notify-send" | |
# get pid of user dbus process | |
DBUS_PID=`ps ax | grep $USER_DBUS_PROCESS_NAME | grep -v grep | awk '{ print $1 }'` | |
# get DBUS_SESSION_BUS_ADDRESS variable | |
DBUS_SESSION=`grep -z DBUS_SESSION_BUS_ADDRESS /proc/$DBUS_PID/environ | sed -e s/DBUS_SESSION_BUS_ADDRESS=//` | |
# send notify | |
DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION su -c "$NOTIFY_SEND_BIN \"$TITLE\" \"$MESSAGE\"" $USER | |
} | |
sleep 2 | |
notifyquota |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment