July 2014
M T W T F S S
 123456
78910111213
14151617181920
21222324252627
28293031  

Categories

July 2014
M T W T F S S
 123456
78910111213
14151617181920
21222324252627
28293031  

awk

USAGE

Unix: awk ‘/pattern/ {print “$1”}’ # standard Unix shells DOS/Win: awk ‘/pattern/ {print “$1”}’ # okay for DJGPP compiled awk “/pattern/ {print \”$1\”}” # required for Mingw32 Most of my experience comes from version of GNU awk (gawk) compiled for Win32. Note in particular that DJGPP compilations permit the awk script to follow Unix […]

Function in shell script

Function in shell script DESCRIPTION: Function is the piece of code, which executed when we call. When thinking about the function in any computer language, three points comes in mind

1. Writing function code and calling that function when we need 2. Passing arguments to the function 3. Returning value from function

Next i […]

bash printf to variable

If you want to use bash’s printf formatting and store the value into a variable, you can use bash’s print’s -v flag as follows:

calc_elaspsed_time() { local SECONDS=$1 ((h=SECONDS/3600)) ((m=SECONDS%3600/60)) ((s=SECONDS%60)) printf -v ELAPSED_TIME “%02d:%02d:%02d” $h $m $s }

printf Command The built-in printf (print formatted) command prints a message to the screen. You […]

Function in shell script

Function in shell script DESCRIPTION: Function is the piece of code, which executed when we call. When thinking about the function in any computer language, three points comes in mind

1. Writing function code and calling that function when we need 2. Passing arguments to the function 3. Returning value from function

Next i […]

Command line argument in shell script

Command line argument in shell script Passing arguments to the main program when it start is know as command line arguments In shell scripting arguments can be described like below

$0 – shows program name which you running $1 – shows first argument $2 – display second argument $3 – display third argument $n – […]

IBM HTTP Server – SSL Certification Expiration Situation

We saw this in /opt/IBM/HTTPServer/logs/error.log yesterday: –

[Mon Jan 23 14:23:25 2012] [notice] Using config file /opt/IBM/HTTPServer/conf/httpd.conf [Mon Jan 23 14:23:25 2012] [debug] mod_mpmstats.c(189): mpmstats daemon started (pid 4775) [Mon Jan 23 14:23:25 2012] [notice] IBM_HTTP_Server/7.0.0.17 (Unix) configured — resuming normal operations [Mon Jan 23 14:23:25 2012] [info] Server built: Mar 7 2011 15:49:28 [Mon […]

How to mount inactive LVM partitions

Cause This situation occurs because the same UUID is attached to each LVM disk. Any LVM command, such as pvscan or lvscan, fails because of that error. You can find more details about Bug 454645 ” Bringing a snapshot of an LVM on-line on the same system” here: https://bugzilla.redhat.com/show_bug.cgi?id=454645 This situation can also occur when […]

check httpd runing or not

#!/bin/sh SERVICE=’httpd’

if ps ax | grep -v grep | grep $SERVICE > /dev/null then echo “$SERVICE service running, everything is fine” else echo “$SERVICE is not running” echo “$SERVICE is not running!” | mail -s “$SERVICE down” root fi

korn shell (ksh) – for loop

Reading from a file

for line in $(cat /etc/passwd) do echo $line done

Iterate for a range

for number in {1..10} do echo “Current number is $number” done

Loop for values given

for planet in earth mars saturn jupiter do echo “The planet name is $planet” done

Loop for variable containing multiple values

planets=”earth mars […]

If statement and comparison operators

If statement without any brackets: These are used to check the outcome of a command. It return the exist status of command executed after if.

if grep -i oolala lyrics.txt then echo “lyrics.txt file contains oolala” else echo “lyrics.txt file doesn’t contain oolala” fi

if statement with []: These are used to check the […]