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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use LET command

Status
Not open for further replies.

jliang

MIS
Apr 26, 2004
30
US
Hi,

I write a Korn shell script to use LET command to calculate how many processes are running. the syntax is:

LET "activejob='ps -ef|grep 'test.sh'|wc -l '"

but I got syntax error.

Can you help me with this problem?

Many thanks in advance.

Jing
 
Jing:

The LET is optional, and you're using the wrong command substitution character. Use the grave mark ` not the quote ':

activejob=`ps -ef|grep -v 'grep test.sh'|grep 'test.sh'|wc -l `

I also included grep -v to ignore that command in the process table.

You can also use the ksh method of command substituition:

activejob=$(ps -ef|grep -v 'grep test.sh'|grep 'test.sh'|wc -l

Regards,


Ed
 
Hi, ED,

It works fine. Thanks very much

Jing
 
You may also try this:
activejob=$(ps -fe | grep -c '[t]est.sh')

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top