Solaris / Linux Issues with script

Hello,

I run this command from a solaris box and it works just fine. It gives me the kind of output in my file I am looking for which would be for example...

sb1p
rdop
ot2p
ot3p
eimp

However when I do the same thing from a Linux box...

ps -ef | grep nco_p_syslog | grep -v grep | awk '{print $NF}' | awk -F. '{print $1}' > $OMNIHOME/bin/syslogfile.dat

I get this in the file...
/lcl/apps/Tivoli/netcool/omnibus/probes/linux2x86/syslog

Both are using
#!/bin/ksh

I have no idea where it is even getting that long directory path from for the results.

Any ideas?

Thanks in advance.

It's differences between the output of solaris ps and linux ps. You'll probably have to make modifications with allowances for the different OSes. You could probably do some case switching magic to do it all in one script, though.

Anyway, I don't have access to a solaris box at the moment, so my suggestion is to start with the base command and work down from there, adding on the pipes one at a time until you figure out where the difference is.

Do:

ps -ef | grep nco_p_syslog

on both, then compare the output. If you don't understand what each command does, you should spend some time reading the various manual pages until you do.

Ok I have been trying that and did some reading up on awk however I can not seem to find how to only capture the last part.

Currently I do...

ps -ef | grep nco_p_syslog | grep -v grep | awk '{print $NF}' | awk -F. '{print $1}' > $OMNIHOME/bin/syslogfile.dat

Which gives the results of....

/lcl/prd/data/dc000p/dump/bdump/alert_dc000p

I only want the dc000p part to record to the dat file.
For the life of me I can not seem to figure out the awk commands to do that.

Any help would be great also explaining how the awk would work how its being used above. I am very new to it and the stuff I am reading is a bit confusing so far.

I am sooo close!!!

I am now doing this...

ps -ef | grep nco_p_syslog | grep -v grep | awk '{print $NF}' | awk -F_ '{print $2}' >> $OMNIHOME/bin/syslogfile.dat

Which gives this result....

dc000p.log

I just can not figure out how to cut the .log from the end :frowning:

Why not

ps -ef | awk -F. '/nco_p_syslog/ { print $NF }' > $OMNIHOME/bin/syslogfile.dat # Solaris
ps -ef | awk -F'_' '/nco_p_syslog/ { print substr($NF, 1, index($NF, ".")-1) }'  > $OMNIHOME/bin/syslogfile.dat # Linux

Hhhhmmm that gives me this result...

syslog/ { print substr($NF, 1, index($NF, "
dc000p

I only want to capture the dc000p part.

Without trying very hard:

ps -ef | grep nco_p_syslog | grep -v grep | awk '{print $NF}' | awk -F_ '{print $2}' | cut -d '.' -f 1

Maybe? I don't have your output.

That did the trick! Perfect.
Now I just want to understand it and how its working. This awk stuff has me confused.

Well I take that back. Strange. This works when I run it myself from the command line...

#!/bin/ksh
# Create and populate array of db syslog probes which are currently running
ps -ef | grep nco_p_syslog | grep -v grep | awk '{print $NF}' | awk -F. '{print $1}' | cut -d '_' -f 2  > $OMNIHOME/bin/syslogfile.dat
set -A syslog_array
syslogfile_name='syslogfile.dat'

Which results in this in the dat file...

/lcl/prd/data/dc000p/dump/bdump/alert_dc000p

Yet when I do this by hand from the command line...

ps -ef | grep nco_p_syslog | grep -v grep | awk '{print $NF}' | awk -F. '{print $1}' | cut -d '_' -f 2  > $OMNIHOME/bin/syslogfile.dat

Then the results in the dat file are....

dc000p

Why would the results not be the same? :frowning:

Haha, I just realized that I added an unnecessary cut.

If you change your -F_ to a -F. it should work without the cut. Those two commands:

awk -F. '{print $2}'

and

cut -d '.' -f 2

are pretty much identical here. The -F_ in awk tries to split fields using _ as a separator. You want to split using a period. The -d '.' in the cut command is the same thing.

Do just the first part and print what you're getting.

ps -ef | grep nco_p_syslog | grep -v grep

From both the command line and a shell script.

Script...

#!/bin/ksh
ps -ef | grep nco_p_syslog | grep -v grep > $OMNIHOME/bin/syslogfile.dat
set -A syslog_array
syslogfile_name='syslogfile.dat'

Output...

/lcl/apps/Tivoli/netcool/omnibus/probes/linux2x86/syslog

Command line...

ps -ef | grep nco_p_syslog | grep -v grep > $OMNIHOME/bin/syslogfile.dat

Output...

I get nothing... Null. The log file is empty.

Are you sure it's running?

Stop redirecting to the log file for the time being, just let it print right out.

Nope it was not running, sorry :slight_smile:
Ok restarted it and then tried from command line again.

bluemarron:/lcl/apps/Tivoli/netcool/omnibus/probes>ps -ef | grep nco_p_syslog | grep -v grep

This is the results....

tivoli   13226 25357  0 15:49 pts/0    00:00:00 /lcl/apps/Tivoli/netcool/omnibus/probes/linux2x86/nco_p_syslog -manager dc000p.syslog -propsfile /lcl/apps/Tivoli/netcool/omnibus/probes/linux2x86/syslog.dc000p.props -logfile /lcl/prd/data/dc000p/dump/bdump/alert_dc000p.log

So, why is the script returning just part of the output?

Its really strange to me...

I do this from command line...

bluemarron:/lcl/apps/Tivoli/netcool/omnibus/bin>ps -ef | grep nco_p_syslog | grep -v grep | awk '{print $NF}' | awk -F. '{print $1}' | cut -d '_' -f 2

And the results are...

dc000p

Which is perfect.

Yet when I do the same thing from a script....

#!/bin/ksh
# Create and populate array of db syslog probes which are currently running
ps -ef | grep nco_p_syslog | grep -v grep | awk '{print $NF}' | awk -F. '{print $1}' | cut -d '_' -f 2  > $OMNIHOME/bin/syslogfile.dat
set -A syslog_array
syslogfile_name='syslogfile.dat'

The results in the dat file are....

/lcl/prd/data/dc000p/dump/bdump/alert_dc000p

Just do:

ps -ef | grep nco_p_syslog | grep -v grep

from the command line. Then put that same command in a script and run it from the same place you're running the other script from.

#!/bin/sh
ps -ef | grep nco_p_syslog | grep -v grep

And compare the outputs. You're not going to find out what the difference is until you compare the raw output.

It's entirely possible that the results returned will be different depending on a lot of factors, you'll just have to adjust your script to account for those differences.

Ok my 3rd full day at this... :frowning: This thing is driving me nuts!

If I run this myself from the command line....

ps -ef | grep nco_p_syslog | grep -v grep | awk '{print $NF}' | awk -F. '{print $2}'  > $OMNIHOME/bin/syslogfile.dat

The results in the dat file are...

dc000p

Which is perfect. However.....

If I let my script do the same thing....

#!/bin/ksh
# Create and populate array of db syslog probes which are currently running
ps -ef | grep nco_p_syslog | grep -v grep | awk '{print $NF}' | awk -F. '{print $2}'  > $OMNIHOME/bin/syslogfile.dat
set -A syslog_array
syslogfile_name='syslogfile.dat'

The results from the script in the dat file are....

/lcl/apps/Tivoli/netcool/omnibus/probes/linux2x86/syslog

Also this is the results of doing just a ps -ef | grep syslog | grep -v grep....

u@h:w> ps -ef | grep syslog | grep -v grep
root      4556     1  0 Mar18 ?        00:17:40 vxconfigd -x syslog
root      5307     1  0 Apr22 ?        00:00:00 /sbin/syslogd
tivoli   25474  9852  0 09:32 pts/2    00:00:00 tail -f syslogfile.dat
tivoli   27003  7618  0 09:35 pts/3    00:00:00 /lcl/apps/Tivoli/netcool/omnibus/probes/linux2x86/nco_p_syslog -manager dc000p -logfile /lcl/prd/data/dc000p/dump/bdump/alert_dc000p.log -propsfile /lcl/apps/Tivoli/netcool/omnibus/probes/linux2x86/syslog.dc000p.props

I don't get it... What am I doing wrong here? :confused:

Shell is ksh if that helps.

Ok its fixed. The issue was that the script is so long I did not noticed that at the bottom this same dat file was being refilled so the old grep was replacing the new. :slight_smile:

Thanks for all the help!