shell scripting syntax

– Printing/Redirecting PID of current program

echo $$ >/tmp/out.pid

– Comparing floating value –

a=1.34
b=1.21

res=`expr $a > $b` [ if true then res =1 else res =0 ]

– Running a script with a particular user

if [ “$LOGNAME” != “tarique” ]; then
echo
echo “Only user bea can run this script”
echo
exit 1
fi

– Logical AND with if condition

if [[ ! -f /tmp/out.pid && $res -eq 1 ]] ; then

– Nested for loop

for (( j = 0 ; j <=1 ; j++ ))
do
for (( i = 0 ; i <=9 ; i++ ))
do
….
done
done

– Date formatting

D=`date '+%y-%d-%m %H:%M:%S'`

– Adding value of two variables

result=$(($Value1 + $Value2))

– Remote command execution –

ssh tarique@remotesrv 'touch /tmp/test;rm -f /tmp/test'

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: