#!/usr/bin/perl $load = `/usr/bin/uptime`; $load =~ /\s+load average:\s+(\S+),\s+/; #print $1, "\n"; $me = `/bin/hostname`; $load = $1; if ($load > 5.5) { #system("/usr/bin/logger -p daemon.emerg load-ave-alert load $load."); system("/usr/bin/wall load-ave-alert load $load."); $DATE = `/bin/date +'%Y%m%d%H%M'`; open(DOMAIL,"| /bin/mail -s \"load-ave-alert $me load high\" root"); print DOMAIL "$me load is $load at $DATE"; close(DOMAIL); } exit; # It seems likely with all the restrictrions on email servers due to spam, that # the email would work only locally on the Linux system # This script could be fork with more perl scripting on with the "nohup" command # ============================================= #!/usr/bin/bash # bash script to fork the perl script above echo $* (/usr/bin/nohup $* > /tmp/nohup$$.txt &)& ================================================== # you could this for the perl script to fork itself after the first line #!/usr/bin/perl $dofork = 1; if ($dofork) { if (open(PS, "/bin/ps ax | /bin/grep \"ping2failure $target\" | /bin/grep -v gre p |")) { @psax =; close(PS); #print "@psax"; for(@psax) { s/^\s+//g; #print $_; if (/ping2failure $target/) { #print "$_"; ($pid, @stuff) = split(/\s+/); #print "$$ pid is $pid and $stuff[0]\n"; if ($pid != $$) { die "$target already being waited on\n"; # no reason to run if already doing this } } } } # deal with stdin, stdout, stderr, control terminal, and put self # in background $TIOCNOTTY = 0x20007471; close(stdin); open(stdout, ">/dev/null"); open(stderr, ">/dev/null"); if (open(tty, "/dev/tty")) { ioctl(tty, $TIOCNOTTY, 0); close(tty); } if (fork) { exit 0; } }
2022-07-16
Linux Perl script to run to monitor load average and send an a lert
Subscribe to:
Post Comments (Atom)
Script to see network interface connection speed
cat network-speed #!/usr/bin/bash # ethtool enp2s0 | grep Speed ethtool $1 | grep Speed # mii-tool -v enp2s0 mii-tool -v $1 network-speed ...
-
This script with it's two related configuration files worked on Raspberry Pi Raspbian Linux. What was always sketchy was the "dri...
-
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. #Warn ; Recommended for catching common errors. Send...
-
cat network-speed #!/usr/bin/bash # ethtool enp2s0 | grep Speed ethtool $1 | grep Speed # mii-tool -v enp2s0 mii-tool -v $1 network-speed ...
No comments:
Post a Comment