July 2007 Archives

Using Perl to monitor & alert tcp hosts

| 0 Comments | 0 TrackBacks

#!/usr/bin/perl

use IO::Socket;

@servers = ( 'one', 'two', 'three');

foreach (@servers) {

$socket = IO::Socket::INET->new( PeerAddr => $_, PeerPort => '22', Proto => 'tcp'); if ($socket) { #print $_ . " SSH is UP" . "\n"; } else { open(MAIL, "| /usr/sbin/sendmail -oi -n -t"); print MAIL << EMAIL_TO_USER; To: unix\@whoever.com, unixunix\@whoever.com From: mon\@whoever.com Subject: MON Alert - SSH on $_ is DOWN Issue: SSH Port on $_ is DOWN. Business Impact: Cannot remote login into $_. Historical Fixes: Restart SSH via svcadm refresh ssh or service sshd restart EMAIL_TO_USER close MAIL; print $_ . " SSH is DOWN" . "\n"; } };

Using Perl to run a ping host check

| 0 Comments | 0 TrackBacks
#!/usr/bin/perl use Net::Ping; @servers = ( 'one', 'two', 'three'); foreach (@servers) { $p = Net::Ping->new(); if ($p->ping($_)) { #print $_ . " is alive" . "\n"; $p->close(); } else { open(MAIL, "| /usr/sbin/sendmail -oi -n -t"); print MAIL << EMAIL_TO_USER; To: unix\@whoever.com, unixunix\@whoever.com, From: mon\@whoever.com Subject: MON Alert - Cannot Ping $_ Issue: Cannot Ping $_. Business Impact: $_ may be down and unreachable. Historical Fixes: Console into the server. EMAIL_TO_USER close MAIL; print "Cannont Ping " . $_ . "\n"; } }; 

Using Perl to monitor & alert disk space

| 0 Comments | 0 TrackBacks
#!/usr/bin/perl $hostname = (`hostname`); @diskinfo = (`df -hl | grep -v named`); foreach (@diskinfo) { @lines = split (/\s+/, $_); $mount = $lines[5]; $percent = $lines[4]; chop $percent; if ( $percent > 50 ) { #print "Sending Alert for " . $mount . "\n"; open(MAIL, "| /usr/sbin/sendmail -oi -n -t"); print MAIL << EMAIL_TO_USER; To: me\@me.com From: me\@me.com Subject: $hostname - $mount is at $percent percent. Issue: $hostname - $mount is at $percent percent. Resolution: Please clean up unneeded files. EMAIL_TO_USER close MAIL; } } 
#!/usr/bin/perl open ( FILE, "< /etc/hosts" ) or die "Cannot open file \n" ; while ( ) { if (/10.0.1/) { @lines = split(/\s+/, $_); print $lines[1] . "\n"; } } close FILE; 

Download those files using Perl

| 0 Comments | 0 TrackBacks
#!/usr/bin/perl $filenumber = 100; while ($filenumber <= 200){ print "$filenumber" . "\n"; # Linux and Solaris #system("wget http://website/images/file_$filenumber.JPG"); # MacOS X system("curl -LO http://website/images/file_$filenumber.JPG"); $filenumber++; } 

Alias CURL as wget

| 0 Comments | 0 TrackBacks

Add the following into your .bash_profile:

alias wget="echo 'using curl -LO'; curl -LO $1" 

Apache .htaccess

| 0 Comments | 0 TrackBacks

Example:

 AuthType Basic AuthName "Password Required" AuthUserFile /etc/htpasswd require valid-user 

Bash Terminal Colors

| 0 Comments | 0 TrackBacks

Add terminal colors by adding the following lines into your .bash_profile.

export CLICOLOR=1 export LSCOLORS=ExFxCxDxBxegedabagacad