my wireless setup fails several times a day, restarting gnome's network manager helps. I want to automate this and hacked the following perlscript:
#!/usr/bin/perl
use strict;
use warnings;
my $result = system "ping -c1 -W1 192.168.1.1";
if ($result != 0) {
print "No connectivity. Action required...\n";
my $pid = `pgrep nm-applet`;
if ($pid) {
print "Killing current nm-applet instance $pid\n";
system "kill $pid";
}
print "Starting nm-applet...";
exec "nm-applet" or die "couldn't start nm-applet";
} else {
print "Looks all fine. No action required\n";
}
My first test was to just kill nm-applet by hand and running the script manually. It detects no connectivity and just "morphs" into nm-applet, just as intended.
Now the same test but executed by the following cron job:
*/1 * * * * /home/joe/netcheck.pl >> /home/joe/netcheck.log &
The output in netcheck.log is just "Starting nm-applet..." but it doesn't get started. The process just dies immediately.
Any help or possibly other solution appreciated.