Here are a few simple lame scripts I use to do various stuff:-

urlwatch - Monitor URL's for changes

Although not really a script, here's a neat way of merging two files together using the pr(1) command.

pr -m -J -T -S'' File_1 File_2 > File_3
Example:-
File_1File_2File_3
1One1 One
2Two2 Two
3Three3 Three
4Four4 Four
5Five5 Five

Here is a short perl script to add up numbers. Very usefull to pipe the output of other scripts to! ;)

perl -ane 'foreach (@F) {/^ \s* \d+(\.\d*)? \s* $/x && do { $sum += $_; } } BEGIN { $sum=0; } END { print "Total = $sum\n"; }'
Example:-
newdire# ./addnum
1
2
3

Total = 6

To remove/strip non-printable or extended ASCII you can do:
tr -cd '\11\12\40-\176' < $INPUT_FILE > $OUTPUT_FILE

Keeping a counter while in a loop in sh(1) is easy once you know how!

Squid's native logging time format is in seconds January, 1970. Here is a way to get the 'real' date..

#!/usr/bin/perl
# Convert Squid - time since January, 1970 - into normal date format
print scalar(localtime($ARGV[0])), " + 172 msec\n";

You can find out the current date in seconds since 1970 by using perl ( perl -e 'print time(), "\n";' ) or using GNU date ( date +%s ).
There's a good page on GNU date at http://www.gnu.org/software/coreutils/manual/html_node/Examples-of-date.html

Script to do a proxy ping ( ie on host A send a ping from router B to router C ) proxy_ping.sh

Here's a cross-platform unix script to find out how much total memory is availble.

Not really scripts, but some *very* handy bash settings:-

Again, not really script's ... but stuff that should be set-up for a host to work well:-


To match an IP address using grep you can use
egrep "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}" <file>
Only problem with this is it can match some invalid IP's such as 300.300.300.300
If you are plaqued by SSH brute force scans, there's a good whitepaper about it here
Perl String Comparison Operators:
String Operator Numerical Operator
eq==
ne!=
gt>
lt<
ge>=
le<=

EMail : Spam free email address


FSF Europe Supporter GNU generation