bash script sometimes work
Hello guys, i have a problem, i'm working on bash script but the problem is that, only work sometimes, sometimes when i run not work the first condition: follow print the script:
Code:
#!/bin/bash i'm using centos 5.7, 32 bits. thank you, regards. |
Could you explain what you think the following line does:
Code:
ps -ef | grep -v grep | grep 'sync-software' |
Quote:
I replaced this line by: /bin/ps -ef | grep -c 'sync-software', when save this result on a var: then when i run the script print a bad result. by example if i run /bin/ps -ef | grep -c 'sync-software', the result is 0 but if i save this result on a var, and then i try print when i run the script, print a bad result :S This is the code: #!/bin/bash TET=`/bin/ps -ef | grep -c 'sync-software'` echo "$TET" although that the script is not running sometimes print 2, 3, 4, its rare :S |
My reason for the previous question is the greps are in the incorrect order as the grep -v is to remove the false positive of grep 'sync-software' being in the results.
Your second test and results would seem to make little sense unless the -c option is not the standard grep option as per below: Code:
-c, --count whilst the actual command is not running it appears as though it is? |
Quote:
"not working"? thank you, regards, |
What if you try using pgrep, like:
Code:
if (( $(pgrep -c sync-software) > 1 )) |
hello again grail,
i try your code of the follow way: Code:
if (( $(pgrep -c sync-software) > 0 )) > /dev/null; pgrep: invalid option -- c Usage: pgrep [-flvx] [-d DELIM] [-n|-o] [-P PPIDLIST] [-g PGRPLIST] [-s SIDLIST] [-u EUIDLIST] [-U UIDLIST] [-G GIDLIST] [-t TERMLIST] [PATTERN] sync-software.sh: line 11: ((: > 0 : syntax error: operand expected (error token is "> 0 ") |
All times are GMT -5. The time now is 08:07 PM. |