Sunday, March 20, 2011

Day to Day Shell Scripts

Script01: Insertion of numbers right at the beginning of every line in the file
If you are in the VI Prompt:

:1,$!sed '/./=' | sed '/./N; s/\n//'

Script02: Insertion of numbers right at the beginning of every line in the file
If you are at the shell prompt:

sed '/./=' file_name|sed '/./N;s/\n/ /'

Script03: This will go through the list of IP Addresses or Hostname (should be a DNS Env) and start pinging one by one to identify whether that server is pingable or not and update the status to the string.out file.


#!/bin/sh
for i in `cat /tmp/prabhu/ping-test`
do
A=`ping -c1 $i |grep "0% packet loss" | cut -c 36-49`
if [ "$A" == "0% packet loss" ]
then
echo -e "$i\tyes" >> string.out
else
echo -e "$i\tno" >> string.out
fi
done