Archive for the 'UNIX Coding Specialist' Category

UNIX Pipes - event triggers action

Problem
You want to listen on a pipe and perform commands, based on the text sent to the pipe.This could be useful for triggering action based on events;Running code as different users - i.e. allow root or a functional user to run something - just need to allow access to group of users, via permission to […]

UNIX debugging

Problem
You want to debug a running process on Solaris?You want to debug running process on Linux?

Solution
See the example for debugging processes on Solaris or Linux - the syntax shows all system executes and reads.

Example
truss -xall -vall -rall -t'read' -p PID #To run a command and have it produce […]

Shell Tips and Tricks

Problem
You want to trace program execution on Solaris?You want to perform network tracing on Solaris?Perform a text dump of a binary file - or see ascii codes, etc?Generate some random data?List directory contents in 3 columns?Loop through a list of files and perform actions on them?Check for values in vars?Detach a process without it dying.Perform […]

undocument find secret

Problem
You want to find a pattern in a file and have the line displayed.

Solution
I “discovered” this undocument (well in all the doco I’ve ever read), pretty much by accident.Basically find produces a list of files (type f), in the current directory and supplies them individually to the grep command. Ordinarily if grep is supplied […]

Optical Dump

Problem
Ever need to look at a file, but have not been able to - due to hidden control characters, etc.

Solution
Or just needed to see spaces and end of line characters, comparing files, etc. Optical dump or more specifically the od command, can be extremely useful for display ascii characters. See the example.

Example
The basic syntax […]

openssl many uses

Problem
You want to generate a self-signed certificate?Encrypt a message with triple desView base 64 encoded dataGenerate and use random dataTest ciphersMonitor certificate expiry dates

Solution
openssl to the rescue! See examples.

Example
openssl code to generate self-signed certencrypt with tripledesopenssl base64 [ -d ]# encrypted with base64.Useful fortransfering control/binary content - like this:dd bs=1 count=512 if=/dev/urandom | openssl […]

uuencode send attachments

Problem
You want to send an attachment, from UNIX command line or from within a shell script

Solution
uuencode works a treat with Solaris. Not sure on RH Linux, etc.

Example
cat filename | uuencode wat_u_want_attatch_2b_called.ext | mail -s "this is the subject and here is wat u want attach 2b called" email_addrSimple as that, it will send the […]

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 fails.

Example
Add to beginning:bash -c '( msg=`Add to the end:2>&1 > /tmp/logfail.log`; if [ ! -z "$msg" ] ; then echo "$msg" |/bin/mail -s "`/bin/uname -n`:$LOGNAME:`/bin/date`: YOUR MESSAGE" YOUR_MAIL_LIST; fi […]

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. In the example I am allowing access to all ports between 600 and 699 - for udp and tcp traffic.

Example
# grep 600 /etc/sysconfig/iptables-A RH-Firewall-1-INPUT -p tcp -m state –state […]

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.

Example
Openssl tripleDES encrypt command:openssl des3 -salt -in file_to_encrypt -pass pass:_your_password_Place contents to encrypt in the file reference by file_to_encryptReplace your_password with your secretOpenssl will output to stdout - so best to capture like this:myvar=$(the openssl command)Openssl […]