ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
How do I flag the results to specific numbers. In other words, I only want it to print the output on screen or in a file if the results are only "0" or 2000 and greater. Right now if I run the script it will display the actual processes.
I'm not sure exactly what you're trying to do, but you could use an if statement to conditionally write/display your result based on a value and range ( = 0 OR is >= 2000).
CNT=$(ps -ef $PID -m -o THREAD | wc -l)
if [ $CNT -eq 0 -o $CNT -ge 2000 ]
then echo $CNT
fi
The first line sets variable, $CNT, to be equal to your wc -l output.
The second line tests the value against 0 (-eq) and (-o = or) against values greater than or equal to 2000 (-ge). It only ouputs the value if it meets one of those conditions.
By the way your ps syntax looks wrong to me but presumably you've got that working already.
Last edited by MensaWater; 08-12-2011 at 04:01 PM.
CNT=$(ps -ef $PID -m -o THREAD | wc -l)
if [ $CNT -eq 0 -o $CNT -ge 2000 ]
then echo $CNT
fi
The first line sets variable, $CNT, to be equal to your wc -l output.
The second line tests the value against 0 (-eq) and (-o = or) against values greater than or equal to 2000 (-ge). It only ouputs the value if it meets one of those conditions.
By the way your ps syntax looks wrong to me but presumably you've got that working already.
CNT=$(ps -ef $PID -m -o THREAD | wc -l)
if [ $CNT -eq 0 -o $CNT -ge 2000 ]
then echo $CNT
fi
The first line sets variable, $CNT, to be equal to your wc -l output.
The second line tests the value against 0 (-eq) and (-o = or) against values greater than or equal to 2000 (-ge). It only ouputs the value if it meets one of those conditions.
By the way your ps syntax looks wrong to me but presumably you've got that working already.
Hi Mensa, I received some further clarification and this is what I need the output to come out as. I want to add an ‘else’ statement to output 0 at all other times, just to be sure we get the exit 0 for SiteScope to evaluate.
Meaning anything else less than 2000 should come up as only a value as 0.
I tried this, but it keeps erring out. Perhaps I am doing something wrong with my scripting.
So then you have what you need ... unless there is another question that I cannot see??
@Kevin - I never bothered to test OPs ps because he seems to imply that it works for him and the arithmetic seemed to be the difficulty (could be wrong of course )
So then you have what you need ... unless there is another question that I cannot see??
@Kevin - I never bothered to test OPs ps because he seems to imply that it works for him and the arithmetic seemed to be the difficulty (could be wrong of course )
Yes, the o THREADS works internally for me. What I do need is a way to push a value of 0 if the count is below 2000. Unfortunately it gives me an eror.
0403-057 Syntax error at line 6 : `then' is not matched.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.