[Solved] Help with condition


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [Solved] Help with condition
# 1  
Old 01-26-2014
[Solved] Help with condition

I have below code, I am checking on one server where ppp.sh process not running it is perfectly fine, when i am checking the same script on another server where ppp.sh script is running, it is throwing error "too many arguments", how to avoid this. If i will check on server where process running it shows "ppp process running" and if i will check on server where process not running it shows error "ppp process stop"



Code:
count=$(ps -ef | grep ppp.sh | grep -v grep)

if [ ${count:-0} -ge 2 ]
then
echo "PPP process running "
else
echo "PPP process stop "
fi

# 2  
Old 01-26-2014
I think you meant to count the lines.
Code:
count=$(ps -ef | grep ppp.sh | grep -v grep| wc -l)

# 3  
Old 01-26-2014
Not sure about your variable count. If you want to avoid error getting displayed, then you can redirect to /dev/null and you can check exit status $?, where exit code 0 is true and 1 is false.
# 4  
Old 01-26-2014
Or, using one less process:
Code:
count=$(ps -ef | grep ppp.sh | grep -cv grep)

# 5  
Old 01-26-2014
Thanks so much for your help, problem solve.
# 6  
Old 01-26-2014
With the [ ] trick grep does not find its own args
Code:
count=$(ps -ef | grep -c "[p]pp.sh")

A perhaps more precise match is
Code:
count=$(ps -ef | grep -wc "[p]pp\.sh")


Last edited by MadeInGermany; 01-26-2014 at 03:21 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[Solved] How to stop script at certain condition?

Hi Gurus, my script likes below if ;then if ; then exit 30 fi if for loop do done I want to if condition1 is true, it exit the execution the script completely with error code 30. but right now it still exe for loop. I try to add below if ;then if ; then ... (3 Replies)
Discussion started by: ken6503
3 Replies

2. Shell Programming and Scripting

If condition return 0 even when it fails to satisfy te condition

HI My doubt may be basic one but I need to get it clarified.. When i use "if" condition that checks for many AND, OR logical conditions like if ]; then return 0 fi Even the if condition fails it returns as zero.. Any clue.. But if i add else condition like if ]; ... (2 Replies)
Discussion started by: Priya Amaresh
2 Replies

3. Shell Programming and Scripting

if condition

if chr1:109457160 1 109457160 99.1735537190083 + chr1:109457233 1 109457233 99.1735537190083 - chr1:109457614 1 109457614 99.1735537190083 + chr1:109457618 1 109457618 100 + chr1:109457943 1 109457943 100 - chr1:109458224 1 109458224 99.1735537190083 - file1.txt If 6th column in... (3 Replies)
Discussion started by: johnkim0806
3 Replies

4. Shell Programming and Scripting

[SOLVED] Sorting file and get everything on same line on condition

Good afternoon! I am a perl newbie. I hope you will be patient with me. I have a script that needs to be written in perl. I can't do it in awk or shell scripting. Here is the script: #!/usr/bin/perl use POSIX qw(strftime); use FileHandle; use Getopt::Long; use IO::Handle;... (0 Replies)
Discussion started by: brianjb
0 Replies

5. UNIX for Dummies Questions & Answers

[Solved] Delete files with condition

I have a directory containing thousands of items “video files”, these items were generated by an application, which generates two items with the same name but with different extensions “.avi and .mp4”. There was a tool in my application to remove one item @ a time. Later I found this tool removes... (5 Replies)
Discussion started by: awadeid
5 Replies

6. Shell Programming and Scripting

redirect stdout echo command in condition A run in condition B

hi, I have some problems in my simple script about the redirect echo stdout command inside a condition. Why is the echo command inside the elif still execute in the else command Here are my simple script After check on the two diff output the echo stdout redirect is present in two diff... (3 Replies)
Discussion started by: jao_madn
3 Replies

7. HP-UX

Difference between [condition] and [[condition]] and ((condition)) when used with if condition

Executed the following if conditions .. and got different results . only (( )) gave correct o/p with all scenarios . Can anybody please let me know what is the difference between and ] and ((condition)) when used with if condition. And why each condition gave different result. 1.... (2 Replies)
Discussion started by: soumyabubun
2 Replies

8. Shell Programming and Scripting

[solved] merging two files and writing to another file- solved

i have two files as file1: 1 2 3 file2: a b c and the output should be: file3: 1~a 2~b 3~c (1 Reply)
Discussion started by: mlpathir
1 Replies

9. Shell Programming and Scripting

if condition

Hi how to write this: if then usage fi thx (3 Replies)
Discussion started by: melanie_pfefer
3 Replies

10. Shell Programming and Scripting

if condition ...

i have following if condition if above statement is case sensitive.....what is syntax if i have to make above comparision case insensetive (4 Replies)
Discussion started by: mahabunta
4 Replies
Login or Register to Ask a Question