Email upon cron failure

Problem You want to receive an email upon cron job failure. Solution The example code can be wrapped around a normal cronjob, to send an email if the cron...

awk line length and average

Problem You want to display line lengths – then average line length of file. Solution Snip using awk – see example. Example awk ' { thislen=length($0);...

Linux IPTables Open port range.

Problem Had to find out how to allow a range with iptables recently, whilst setting up Samba and NFS. Solution Always take a backup first, then vi /etc/sysconfig/iptables....

Encrypt TripleDES

Problem You want to encrypt some text, using the tripleDES Cipher. Solution Openssl is a beautiful command, that performs many functions. See example....

Generate self-signed cert openssl

Problem You want to generate a self-signed certificate, for use with a web server.This will allow you to communicate with your web server over HTTPS, effectively...

Testing Cipher Strength

Problem You want to be sure that your web site is only serving 128 bits! Solution Use openssl s_client – with specific ciphers – see the example....

SSL Certification Expiry Date Checker

Problem You want to automate checking expiry of SSL (HTTPS) Certificate expiry. Solution The link to the script is displayed in examples. It connects to...

Compare Java Certificate Stores – cacerts

Problem You want to compare two cacerts java certificate stores.Say comparing development server against prod, to ensure they both have same certs stored...

Generate Random Data with dd

Problem You want to generate 512 bytes of random data, using UNIX dd (disk to disk) command. Solution Using /dev/random blocks waiting for truly random...

While For Loops

Problem You want to loop around a number of times and perform an action. Solution Being able to loop around a given number of times, fully utilizes the...

Split output over columns

Problem Ever wanted to produce columns of output, rather than your output spilling off the screen. Solution Useful command for this is paste, see example...

Looping with For and While

Problem You want to loop a number of times in UNIX. Solution Being able to loop around a given number of times, fully utilizes the power of UNIX. See the...

Check var for pattern

Problem You want to check a variable for a given pattern. Solution This is my personal favorite way to check for values in vars. See examples. Example...

Detach proc from shell

Problem When you exit your shell, the processes you’ve kicked off die. Solution If you start a process with nohop (ignore the hup signal), it will...

Binary Calculator Hex

Problem You want to perform some arithmetic with UNIX. Solution The binary calculator, installed with pretty much all version of UNIX, can be used for...

VI Tips

Problem Started using vi probably 13 years ago and ever so often, still learn new tricks with it! 🙂Some of my favorites are: turning on control characters;...

AJAX Gotcha Browser caching

Problem Spent many hours debug my code on elizaclaire.darlingranges.com.I kept wondering why, whenever I updated the code – it did not get reflect...

AJAX And Javascript Functions Gotcha

Problem Spent many further hours debug my code on elizaclaire.darlingranges.com.None of my javascript functions worked, in the resulting sub-request. Tried...

AWK Find field number

Problem Ever needed to print out one column with awk, but do not know the field number? Solution Here I’m running df and looking for a field with...

AWK Print line number

Problem Ever wanted to display a line number, with each matching record from awk. Useful as a way of counting the number of matching lines too. Solution...

Send HTML email from command line

Problem Need to send an email from UNIX command line, that contains HTML content? Solution Most useful when generating statistics, etc – just spin...

Debugging shell scripts

Problem You need to debug a shell script. Solution Most shells (zsh, ksh, bash …) can either run with a minus x (-x) option or by specifying set...

Procs started by cron

Problem Sometimes you want to list all processes that have been initiated by cron. Solution To do this you first need to know the Process ID (PID) of the...

Proc run timings

Problem You want to ascertain how long your script takes to run, displaying thousands of seconds and including CPU utilization. Solution Just use the time...

Ways Display Procs

Problem You want to display processes, commands within the process tree. Solution There are a number of ways to search the process tree.Here are a few:Show...

Using FIFOs

Problem You want to create and use an UNIX FIFO. Solution FIFO means first in, first out.To create a FIFO (also called a named pipe), UNIX supplies the...

Find pattern in file

Problem You need to find a pattern in a file. Using regular expression. Solution Normal command to display something in a file, is grep.grep "pattern"...

SED extract line from file

Problem You want to extract a specific line number from a file. Solution Once you have your line number – see previous post on grep, we can extract...

SED Tips

Problem Following on from the last post on removing lines with sed, how do we use sed to substitute output on the fly? Solution This says substitute occurences...

Read File To Var

Problem You want to read a file into a Perl variable. Solution Following on from the Simple PHP demo of opening and reading contents of files, here is...