This is a list of handy one liners - adding onto the ones out there... grep for text in a multiline blob - this redefines the newline as a single space char - case insensitive (i), and over line breaks (s) cat somefile | perl -lne '$/ = " "; print if /text_to_match/is;'
Count lines ala "
user@vps2 ~/ $ ps -ef | perl -lne 'while (<>) { ++$i; } print $i;'
93
user@vps2 ~/ $ ps -ef | wc -l
93
Find IP's that failed 25 times or more and send to /etc/hosts.deny - 25 is set at the end of the statement: root@host ~ # egrep -e 'IN Blocked' /var/log/messages | tail -5000 | perl -lne '/(\d+\.\d+\.\d+\.\d+)/; print $1;' | sort | uniq -c | sort -n | perl -lne '/(\d+)\s+(\d+\.\d+\.\d+\.\d+)/; $d=`date`; chomp $d; print "# Too many failures $d\nALL: $2" if ($1 >= 25);' >> /etc/hosts.deny |
|||
