November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

Categories

November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

if condition-integer expression expected

if condition-integer expression expected

ADV1=94.3
Quantity=96.3
if [ $Quantity -eq $ADV1 ]; then
echo “quantity is greter”
fi

echo “” | nawk -v ADV1=94.3 -v Quantity=96.3 ‘{if(ADV1 $Quantity “|bc) -eq 1 ] ; then
echo “$ADV1 is greter”
else
echo “$Quantity is greater”
fi

ADV1=94.3
Quantity=96.3
if [ $Quantity -gt $ADV1 ]; then
echo “quantity is greter”
fi

if [ “$var1” -lt “$var2” ]; then
echo “$var1 is lt $var2”
else
echo “$var2 is lt $var1”
fi

if ((var1> /tmp/log&
# background cmd pid
pid=$!
# loop to monitor running background cmd
while :
do
ps ax | grep $pid | grep -v grep
ret=$?
if test “$ret” != “0”
then
echo “Monitored pid ended”
exit
fi
sleep 5

done

wait $pid
echo $?

!/bin/bash
CHECK=$0
SERVICE=$1
DATE=`date`
OUTPUT=$(ps aux | grep -v grep | grep -v $CHECK |grep $1)
echo $OUTPUT
if [ “${#OUTPUT}” -gt 0 ] ;
then echo “$DATE: $SERVICE service running, everything is fine”
else echo “$DATE: $SERVICE is not running”
fi

#!/bin/sh

SERVICE=”$1″
RESULT=`ps -a | sed -n /${SERVICE}/p`

if [ “${RESULT:-null}” = null ]; then
echo “not running”
else
echo “running”
fi

#!/bin/bash
ps axho comm| grep $1 > /dev/null
result=$?
echo “exit code: ${result}”
if [ “${result}” -eq “0” ] ; then
echo “`date`: $SERVICE service running, everything is fine”
else
echo “`date`: $SERVICE is not running”
/etc/init.d/$1 restart
fi

#!/bin/sh
SERVICE=$1
if ps ax | grep -v grep | grep -v $0 | grep $SERVICE > /dev/null
then
echo “$SERVICE service running, everything is fine”
else
echo “$SERVICE is not running”
fi

!/bin/sh

PROCESS=”$1″
PROCANDARGS=$*

while :
do
RESULT=`pgrep ${PROCESS}`

if [ “${RESULT:-null}” = null ]; then
echo “${PROCESS} not running, starting “$PROCANDARGS
$PROCANDARGS &
else
echo “running”
fi
sleep 10
done

#!/bin/bash
ps_out=`ps -ef | grep $1 | grep -v ‘grep’ | grep -v $0`
result=$(echo $ps_out | grep “$1”)
if [[ “$result” != “” ]];then
echo “Running”
else
echo “Not Running”
fi

# simulate a long process that will have an identifiable exit code
(sleep 15 ; /bin/false) &
my_pid=$!

while ps | grep ” $my_pid ” # might also need | grep -v grep here
do
echo $my_pid is still in the ps output. Must still be running.
sleep 3
done

echo Oh, it looks like the process is done.
wait $my_pid
my_status=$?
echo The exit status of the process was $my_status

#!/bin/sh

cmd() { sleep 5; exit 24; }

cmd & # Run the long running process
pid=$! # Record the pid

# Spawn a process that coninually reports that the command is still running
while echo “$(date): $pid is still running”; do sleep 1; done &
echoer=$!

# Set a trap to kill the reporter when the process finishes
trap ‘kill $echoer’ 0

# Wait for the process to finish
if wait $pid; then
echo “cmd succeeded”
else
echo “cmd FAILED!! (returned $?)”
fi

#!/bin/bash
….
doSomething &
local pid=$!
while [ -d /proc/$pid ]; do # While directory exists, the process is running
doSomethingElse
….
else # when directory is removed from /proc, process has ended
wait $pid
local exit_status=$?
done

#!/bin/sh
cd /usr/src/linux
if [ “$?” -eq “0” ]; then
make dep
if [ “$?” -eq “0” ]; then
make bzImage
if [ “$?” -eq “0” ]; then
make modules
if [ “$?” -eq “0” ]; then
make modules_install
if [ “$?” -eq “0” ]; then
cp arch/i386/boot/bzImage /boot/my-new-kernel
if [ “$?” -eq “0” ]; then
cp System.map /boot/
if [ “$?” -eq “0” ]; then
echo “Your new kernel awaits, m’lord.”
fi
fi
fi
fi
fi
fi
fi
fi

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>