1829347 Members
13555 Online
109991 Solutions
New Discussion

Re: script help req.

 
SOLVED
Go to solution
Archana1
Frequent Advisor

script help req.

My dynamic log contents only below three entries:
red
blue
green

I am looking for a script which looks contents of log and incase any entry is missing it will put into another log.

FILE=`cat cl`
for i in `$FILE`
do
if [ "$i" = "red" ] || [ "$i" = "blue" ] || [ "$i" = "green" ]
then
echo ""
else
echo $i > moni.log
fi
done


This SCript is not working.. Pls help
10 REPLIES 10
rariasn
Honored Contributor

Re: script help req.

James R. Ferguson
Acclaimed Contributor
Solution

Re: script help req.

Hi:

Your script is running infinitely.

Instead of:

# for i in `$FILE`

...you want:

# for i in "$FILE"

That is, you don't want back-ticks to cause the shell to execute.

The use of back-ticks is discouraged in POSIX compliant shells. The preferred notation for:

# FILE=`cat cl`

...would be:

# FILE=$(cat cl)

Regards!

...JRF...
Archana1
Frequent Advisor

Re: script help req.

James thanks for response.

I wrote an script - which checks for process status. In case process not running should puts other log file stating process is down.

ARTIS=`ps -xef | grep java | grep ArtePryServer | awk '{print $(NF-2)}' | cut -c 54-74`
VAR=`ps -ef | grep 4445 | grep -v grep |awk '{print $NF}'`

if [ "$ARTIS" = ???? ]
then
echo "ARTIS down"
else
exit
fi
if [ "VAR" = ??? ]
then
.
.
.


Iam stuck with statement ... Pls help me..
Just incase required the real variable values are :-

ARTIS=ArtemisServer
VAR=4445
Dennis Handly
Acclaimed Contributor

Re: script help req.

>if [ "$ARTIS" = ??? ]; then
>if [ "$VAR" = ??? ]; then

What should $ARTIS and $VAR be?
If you want to check for empty you could use the obvious:
if [ "$ARTIS" = "" ]; then

Or:
if [ -z "$ARTIS" ]; then
Elmar P. Kolkman
Honored Contributor

Re: script help req.

Simplest solution:

if [ -z "$ARTIS" ]
then
echo "Artis is down"
fi

(There came no matching output from the ps command.)
Every problem has at least one solution. Only some solutions are harder to find.
Archana1
Frequent Advisor

Re: script help req.

I have created script as below. Some times shell give 'return 1' Error, Although process up and running fine.
Any possibility to avoid this 'return 1' error.

#/usr/bin/sh
export PIDWEB=`ps -ef |grep 4444|grep start |grep -v grep|awk '{print $NF}'`
if [ -z "$PIDWEB" ]
then
echo "down" > /var/opt/admin/javanode.log
else
echo "up" > /tmp/javanode.log
echo "" > /var/opt/admin/javanode.log
fi
James R. Ferguson
Acclaimed Contributor

Re: script help req.

Hi:

> I have created script as below. Some times shell give 'return 1' Error, Although process up and running fine.

You aren't testing the return code of anything in the script you have shown.

Be aware that 'grep'ing for a process needs to be very explicit. You can find or miss matches with ease.

Regards!

...JRF...
James R. Ferguson
Acclaimed Contributor

Re: script help req.

Hi (again):

I would add, that instead of doing:

# export PIDWEB=`ps -ef |grep 4444|grep start |grep -v grep|awk '{print $NF}'`

...and you know the name of the process in question, do something like this:

# PIDWEB=$(UNIX95= ps -C syslogd -opid= -oargs=)

This example assumes that the process you want to verify is the 'syslogd' daemon. If it's running, the 'PIDWEB' variable would contain something like:

756 /usr/sbin/syslogd -N -D -v

You can examine the manpages for 'ps' to see the various pieces of data that you can collect. Here, I chose to capture the pid and the arguments used to start 'syslogd'.

Using the XPG4 (UNIX95) behavior for 'ps' allows you to specifically select a process by name ('-C') and to explicitly choose the data you want returned. Do *not* set 'UNIX95' for other than the duration of the command line. That's what the 'UNIX95= ps ...' notation does. There is no semicolon following the "=", only whitespace.

Regards!

...JRF...
Archana1
Frequent Advisor

Re: script help req.

This return code is creating one alert for OPS team.
Is there any way I can suppress/avoid this return value within the script..

James R. Ferguson
Acclaimed Contributor

Re: script help req.

Hi (again):

> This return code is creating one alert for OPS team. Is there any way I can suppress/avoid this return value within the script..

Other than the return code of the last command executed, your script isn't returning anything other than the success or failure of the last command executed. I don't think you are showing everything!

Regards!

...JRF...