Shashikant shah

Wednesday 26 November 2014

How to replace particular word in a file

#!/bin/bash

echo -n "Enter File Name :- "
read name

echo -n "Enter File Path :- "
read path

file=`echo $path$name` > /dev/null

if [[ ! -f "$file" ]];then

        echo "'$file' Please Check Path & File Name..!"
exit 2
fi

echo -n "Enter Replace Word :- "
read old

E=`grep -oh "\W*\w*$old\w*\W*" $file | head -1 && grep -oh "\W*\w*$old\w*\W*" $file | sort -n | grep -w $old | head -1`

echo -n $E > /tmp/a

s=`grep -oh "\W*\w*$old\w*\W*" /tmp/a | sort | head -1`

if [[ "$old" != $s ]];then

        echo "'$old' Word is not Found in file."
exit 3
else

echo -n "Enter New Word :-  "
read new
f=`cp -r $file $file.old`
        echo "backup is created"

for runtime in 1 2 3 4 5
do
E=`sed -i "s/\(^\| \ .\)$old\( \|$\)/$new /g" $file | sed -i "s/\(.^\| \)$old\( \|$\)/ $new /g" $file`
done
echo "File has been replaces"
exit 0
fi

Tuesday 18 November 2014

RPM Details


1. Find out what package a file belongs.

# rpm -qf /etc/passwd

2. Remove and installed package without checking for dependencies.

# rpm -ev --nodeps {rpmname}

# rpm -ivh --nodeps {rpmname}

3.Display list all installed packages

# rpm -qa {rpmname}

4.Display installed information along with package version and short description

# rpm -qi {package}

5.Display list of configuration file for a package

# rpm -qc {pacakge-name}

6.Find out what dependencies a rpm file has

# rpm -qpR {.rpm-file}

7.Display list of all recently installed RPMs

# rpm -qa --last

8.How To rebuild Corrupted RPM Database.

# cd /var/lib
# rm __db*
# rpm --rebuilddb
# rpmdb_verify Packages

Thursday 13 November 2014

BASH Script for service check

  
#!/bin/bash
PIDFILE=/tmp/phonemonitor.pid
PHPSCRIPT=/usr/local/phonemonitor/monitor.php
echo 'Checking if our monitor script is active'
if [ -f $PIDFILE ] ; then
    PID=`cat $PIDFILE`
    if ps ax | grep -v grep | grep $PID > /dev/null
    then
        echo "Script is running"
    else
        echo "Script is not running - attempting to Start"
        rm -f $PIDFILE
        php $PHPSCRIPT & echo $! > $PIDFILE&
    fi
else
    echo "Script is not running - attempting to Start"
    php $PHPSCRIPT & echo $! > $PIDFILE&
fi