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_1 | File_2 | File_3 |
| 1 | One | 1 One |
| 2 | Two | 2 Two |
| 3 | Three | 3 Three |
| 4 | Four | 4 Four |
| 5 | Five | 5 Five |
Here is a short perl script to add up numbers. Very usefull to pipe the output of other scripts to! ;)
Example:-
perl -ane 'foreach (@F) {/^ \s* \d+(\.\d*)? \s* $/x && do { $sum += $_; } } BEGIN { $sum=0; } END { print "Total = $sum\n"; }'
newdire# ./addnum
1
2
3
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:-
export PS1='\[\033[01;31m\]\h \[\033[01;34m\]\W \$ \[\033[00m\]' - Set your command prompt to something useful, ie hostname, username and cwd.export PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"' - Make your xterm title update with username, hostname and pwd after each command is runAgain, not really script's ... but stuff that should be set-up for a host to work well:-
Configuring a kernel for more open files and sockets. The details are extremely system dependent and change with the operating system version. Be sure to verify the following information with your system tuning guide:
Linux kernel parameters can be specified in /etc/sysctl.conf and can also be changed with sysctl commands:
fs.file-max=16384 kernel.threads-max=2048
Some FreeBSD kernel parameters can be specified in /boot/loader.conf, and some can be changed with sysctl commands. Which is which depends on the version.
kern.ipc.maxsockets="5000" kern.ipc.nmbclusters="65536" kern.maxproc="2048" kern.maxfiles="16384" kern.maxfilesperproc="16384"
Solaris kernel parameters can be specified in /etc/system, as described in the Solaris FAQ entry titled "How can I increase the number of file descriptors per process?"
* set hard limit on file descriptors set rlim_fd_max = 4096 * set soft limit on file descriptors set rlim_fd_cur = 1024
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
| String Operator | Numerical Operator |
| eq | == |
| ne | != |
| gt | > |
| lt | < |
| ge | >= |
| le | <= |