1833744 Members
3004 Online
110063 Solutions
New Discussion

shell script help

 
SOLVED
Go to solution
Murat SULUHAN
Honored Contributor

shell script help

Hi

this command works from command line

ps -ef|grep `ps -ex|grep -v grep|grep tahoe| awk '{print $1}'`

but I cannot run within shell script, when I run the shell script I got these errors

grep: can't open 11632
grep: can't open 19916


I am using HP-UX 11.0, POSIX Shell

Best Regards
Murat
Murat Suluhan
8 REPLIES 8
twang
Honored Contributor

Re: shell script help

Try this and see if it works:
ps_num=`ps -ex|grep -v grep|grep tahoe| awk '{print $1}'`
ps -ef|grep $ps_num
Massimo Bianchi
Honored Contributor

Re: shell script help

Hi,
i don't think that it will work proerly also from command line.


grep expect two argument, a search patterna and a file name.

if

`ps -ex|grep -v grep|grep tahoe| awk '{print $1}'`

returns more than 1 string, the first will be used as a search pattern, and the second as the file name.

To have it working (don't know if is what you want..)

`ps -ex|grep -v grep|grep tahoe| awk '{print $1}'` > /tmp/tmp.$$

ps -ef|grep -f /tmp/tmp.$$

rm /tmp/tmp.$$


Massimo





Massimo Bianchi
Honored Contributor

Re: shell script help

Hi,
sorry, i made a typo:

ps -ex|grep -v grep|grep tahoe| awk '{print $1}' > /tmp/tmp.$$


without the "`...`"

Massimo
Murat SULUHAN
Honored Contributor

Re: shell script help

Hi


re Twang
I solved this problem like your solution, but I want to know my error about shell scripting :))

re Massimo
ps -ef | grep `ps -ex | grep -v grep | grep tahoe| awk '{print $1}'`

is works, I am sure, look below :)

tahoe:/home/root#ps -ef | grep `ps -ex | grep -v grep | grep tahoe| awk '{print $1}'`
root 11632 11618 0 Jul 17 ? 62:09 /opt/weblogic7/jdk131_08/bin/../bin/PA_RISC2.0/native_thread
tahoe:/home/root#


Thanx for your responses

Best Regards
Murat SULUHAN
Murat Suluhan
Murat SULUHAN
Honored Contributor

Re: shell script help

Hi

re Twang
I solved this problem like your solution, but I want to know my error about shell scripting :))

*************************

re Massimo Bianchi

ps -ef | grep `ps -ex | grep -v grep | grep tahoe| awk '{print $1}'`

is works, I am sure, look below

tahoe:/home/root#ps -ef | grep `ps -ex | grep -v grep | grep tahoe| awk '{print $1}'`
root 11632 11618 0 Jul 17 ? 62:09 /opt/weblogic7/jdk131_08/bin/../bin/PA_RISC2.0/native_thread
tahoe:/home/root#


Thanx for your responses

Best Regards
Murat SULUHAN

Murat Suluhan
Massimo Bianchi
Honored Contributor
Solution

Re: shell script help

Hi,
it works because you have only one line matching.

When you start the script in backgroung, there may be some other line of ps matching, this is my though.

Try my solution, without the rm of the file.

How many lines do you get there ?

Massimo
Murat SULUHAN
Honored Contributor

Re: shell script help

Hi

first of all I am so sorry for two same message,


I understand what do you mean, I modify the script like that

ps -ef | grep `ps -ex | grep -v grep | grep weblogic7 | grep tahoe| awk '{print $1}'`

it works now

Thank you so much

Best Regards
Murat

PS: We have two separate weblogic installation in the same server with lots of domains, I am developing general administration script
Murat Suluhan
Bill Hassell
Honored Contributor

Re: shell script help

As a general note about use of the obsolete grave accent form (as in echo `hostname`). This was replaced by $(...) many years ago and is always thye preferred way to represent stdout from a set of commands. $() also can be nested, something that is particularly difficult with ``

Another simplification that you might use is to have ps do all your searching for you:

UNIX95= ps -e -C native_thread | grep tahoe

ps has a LONG list of features that are not available unless the UNIX95 variable is defined. Since UNIX95 can change the behavior of other processes and libraries, it is recommended never to export or permanently define the variable. Just add it in front of the command and it will exist only for the one command.

The -C option will search for the exact process name, something that grep cannot do. For instance:

ps -ef | grep sh
UNIX95= ps -fC sh

The first form cathes unhasdaemon and other unrelated processes (such as those owned by user=bashir) while the second form looks at the basename of the process for an exact match (won't find ksh for instance).


Bill Hassell, sysadmin