Skip to content

Instantly share code, notes, and snippets.

@roflmao
Last active December 15, 2015 17:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roflmao/5293963 to your computer and use it in GitHub Desktop.
Save roflmao/5293963 to your computer and use it in GitHub Desktop.
raspberry pi wifi keepalive script
#!/usr/bin/perl
# NAME wifi-check.pl
# AUTHOR Kronalias
# PROVIDES Checks to see if WiFi has a network IP and if not restarts WiFi
#
# CRONTAB Run wifi-check.pl every minute
# */1 * * * * /home/pi/my/scripts/wifi-check.pl >> /mnt/ramdisk/wifi-check.log
#
# HISTORY
# 1.01 - Base version
my $name = 'wifi-check.pl';
my $version = 1.01;
use strict;
use warnings;
my $wlan = 'wlan0';
use POSIX "strftime";
print strftime("%H:%M:%S %a %d %b %Y", localtime(time())) . ' ' . $name . ' ' . $version . ' ';
if (`/sbin/ifconfig wlan0 | /bin/grep "inet addr:"`) {
print "Up\n";
} else {
print "Down\n";
`/usr/bin/sudo /sbin/ifdown $wlan`;
sleep 5;
`/usr/bin/sudo /sbin/ifup --force $wlan`;
}
exit;
@layouterlimits
Copy link

Why not restarting the network service?
/etc/init.d/networking restart

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment