Skip to main content

Alert me when a Wi-Fi network is detected



Alert me when a Wi-Fi network is detected
In this post I will tell you how to get alerted whenever a Wi-Fi network is detected.
First you have to copy the following script and save in an empty document.
       

#!/bin/bash

#wifidetect - Alert when new wireless

#Licensed under the standard MIT license:
#Copyright 2013 Radu Rădeanu (http://askubuntu.com/users/147044/).
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE

DISPLAY=:0.0
#change 'username' with your username
HOME=/home/username/
XAUTHORITY=$HOME/.Xauthority
export DISPLAY XAUTHORITY HOME

#check if you run the script as root
if [ "$(whoami)" != "root" ]; then
notify-send -i error "You must to run $(basename $0) script as root."
echo "You must to run $(basename $0) script as root."
exit
fi

#check if beep is installed
if [ ! -n "$(dpkg -s beep 2>/dev/null | grep 'Status: install ok installed')" ]; then
notify-send -i error "The package 'beep' must to be installed before to run $(basename $0)." "Use 'sudo apt-get install beep' command in terminal to install it."
echo -e "The package 'beep' must to be installed before to run $(basename $0)\nUse 'sudo apt-get install beep' command in terminal to install it."
exit
fi

[ -f /tmp/networks ] || > /tmp/networks

#scan for networks - need root privileges
#change 'wlan0' with your interface name of your wireless network card; you can find it using 'ls /sys/class/net' command
sudo iwlist wlan0 scan | grep -E "Address|ESSID" | awk 'BEGIN {FS=": |\""} {print $2}' | sed 'N;s/\n/ /' | sort > /tmp/new_networks

#check if there are new networks
new_networks=$(comm -1 -3 /tmp/networks /tmp/new_networks)
new_essids=$(echo $new_networks | sed "s/..:..:..:..:..:..//g" | sed "s/ /, /g")

if [ -n "$new_networks" ]; then #if there are new networks
#send a graphical notification
notify-send -i /usr/share/app-install/icons/wifi-radar.svg "New network(s) detected:" "$new_essids"
#send a sound notification
pcspkr_on=$(lsmod | grep pcspkr)
if [ -n "$pcspkr_on" ]; then
beep
else
sudo modprobe pcspkr
beep
sudo modprobe -r pcspkr
fi

#change the old list of networks with the list containing new networks
#the networks that were detected in the previous scan and wern't detected this time will be removed from the list
cat /tmp/new_networks > /tmp/networks

#if you want that only the new networks detected (who were not detected in previous scans) to be added to list, comment the previous line and and uncomment the following three
#cat /tmp/networks > /tmp/tmp_networks
#cat /tmp/new_networks >> /tmp/tmp_networks
#cat /tmp/tmp_networks | sort | uniq > /tmp/networks
fi



To create an empty document open the file manager and navigate to the folder where you want to create the document. Now right click in the folder and select create text document and then empty document.
image of the copied script
Now copy the following script and paste it into the empty document.



Note: You have to change in script username with your user name and wlan0 with your interface name of your wireless network card; you can find it using ls /sys/class/net command.
Now save it by selecting save as option in file tab and save it as wifidetect.sh . Note the file extension it is .sh .
save it as wifidetect.sh







Now make the script executable by using the following command:
chmod +x /pathtoscripts/wifidetect
Replace /pathtoscripts/ with your path to the script wifidetect.sh .
Now open a terminal and type
sudo crontab –e
Now add the following line in the crontab entries:
*/1 * * * * /path/to/scripts/wifidetect
your crontab enry should look like this
If you want to play a music file just post a comment and I’ll tell you how to do that.

Popular posts from this blog

INSTALLING MOBILE PARTNER IN LINUX

Most of you who have a Huawei USB modem (data card) might have tried to install mobile partner (dash board) in Linux. Here I will show you how to install mobile partner in Linux. First, you have to copy the folder called Linux in the data card. The files in the data card are not accessible from Linux so copy them from Windows. Now right click the file “install” in the “Linux” folder. Go to the permissions tab and select the check box beside Allow executing as a program. Now open a terminal by pressing CTRL + ALT + Tkeys. Change the working directory to the folder “Linux” by using “cd <path to folder>”. Now type ./install. If you had installed this software in your system before, you will get a prompt: "The software is exist, do you want overwrites? ([Y]/[N])", enter "y" to overwrites or "n" to exit. If you do not had installed this software in your system before, you will get a prompt: "Please input the install path[/usr/local/Mobile_Partner]:"…

How to setup a wifi-hotspot in Ubuntu: The terminal way.

Ubuntu has a "Use as hotspot" mode. But it creates a n ad-hoc network only.Wireless hotspots aren't same as ad hoc networks. Significant difference is there. In short, ad hoc networks aren't supported in most Android, Windows Phone and Blackberry devices (and may be iOS devices too) whereas AP mode Wi-Fi hotspots are.

              It is really simple and easy to setup a hotspot in Ubuntu. We use a tool called ap-hotspot. To install it open a terminal and type the following:

sudo add-apt-repository ppa:nilarimogard/webupd8 sudo apt-get update sudo apt-get install ap-hotspot
             Next, to start the hotspot type the following in a terminal:
sudo ap-hotspot start
It asks you which adapter's internet you want to share, name of the network, password, etc. in an interactive manner. To stop the hotspot type the following n the terminal :
sudo ap-hotspot stop
To configure it type the following in the terminal :
sudo ap-hotspot configure

Unable to lock the administration directory (/var/lib/dpkg/) is another process using it?

PROBLEM:
Some times we get the following error while trying yo install software using apt-get or synaptic packaging manager.
E: Could not get lock /var/lib/dpkg/lock - open (11 Resource temporarily unavailable)
E: Unable to lock the administration directory (/var/lib/dpkg/) is another process using it?


How can we resolve this?
SOLUTION: 
The problem occurs if we are running another applications like synaptic using the directory. So, if this is the case close the applications and try run the command again.
You will also get this message if you forget to use  sudo  when executing an apt command. You can use sudo lsof /var/lib/dpkg/lock to find the process that owns the lock file Then try to kill the process to remove the lock.
**WARNING**
This should be used as last resort. If you use this carelessly you can end up with a broken system.
You can delete the lock file with the following command:
sudo rm /var/lib/apt/lists/lock


You may also need to delete the lock file in the cache directory.
sudo r…