Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Grep problem 3

Status
Not open for further replies.

mrn

MIS
Apr 27, 2001
3,993
GB
I seem to have a problem running grep from a script

ps -elf|grep archive | grep -v grep

works fine from command line, but seems to ignore the grep -v grep when run from script. I'm using ksh on Sol 8.

Anyone got any ideas?


--
| Mike Nixon
| Unix Admin
|
----------------------------
 
apart from the fact that it works for me ...

ps -elf | grep archive | grep -v $$

might work ... maybe

how exactly are you putting it into a file ...
 
Thanks that sorted it

--
| Mike Nixon
| Unix Admin
|
----------------------------
 
No it's not. It works from command line but not from crontab still picks up the greps pid

--
| Mike Nixon
| Unix Admin
|
----------------------------
 
Try doing ps -elf | grep archive | grep -v "grep"
 
I've got it working using root's crontab with

su - username -c command

So I presume it must be something to do with the users shell or Env.

Thanks for your help

--
| Mike Nixon
| Unix Admin
|
----------------------------
 
You could also use pgrep on Solaris 8 which returns the process id of the named process

Another common trick is to use 'ps -ef | grep [a]rchive'
this takes advantage of greps syntax to find archive but not the grep process itself.
 
now that's a nice one, you can have a star for that :)
 
Another suggestion (not that I'm looking for stars or anything!!):

[tt]ps -e | grep archive[/tt]

Since omitting the -f switch doesn't include the command line parameters in the ps output there's no chance that grep will match the search string on the grep command line.

Annihilannic.
 
you won't get a star :)
you'd need the command line argument to work out that 'archive' is the command of the process ...

your answer would work only if you were trying to find a user called 'archive'
 
Uhh... no? These are the columns ps -e usually displays:

[tt]$ ps -e
PID TTY TIME CMD
0 ? 0:01 sched
1 ? 0:49 init
2 ? 0:00 pageout
3 ? 612:54 fsflush
...[/tt]



Annihilannic.
 
ahh ... ok :)

i was wrong ... :)

i admit it ...

but you're still not getting the star ;P
 
But I'll give you one (a star that is) ;-)

--
| Mike Nixon
| Unix Admin
|
----------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top