#!/usr/bin/perl @apm = `/usr/bin/apm -v`; foreach $line (@apm) { if ( ( index $line, "not connected" ) > 1 ) { # If the apm.lock file does not exist if ( !( -e 'apm.lock' ) ) { # We only want this command to run once which is why we have a lock file `wget -O powertrip.html -http-user=admin -http-passwd=yourpassword http://camera_ip/adm/file.cgi?audio_enable=enabled&mot=enabled&email=you\@yourisp.com`; $lock = `/bin/touch amp.lock`; } } else { # The power is back on. Remove the lock file but do not turn off monitoring if ( ( index $line, "connected" ) > 1 ) { $exec = `/bin/rm -f apm.lock`; } } }