mersenneforum.org  

Go Back   mersenneforum.org > Extra Stuff > Linux

Reply
 
Thread Tools
Old 2022-10-17, 23:11   #1
pepi37
 
pepi37's Avatar
 
Dec 2011
After milion nines:)

3×541 Posts
Default if then....

my script
Code:
echo "STATUS OF GFN PROCESS" 
echo "ps -C GFN22 --no-headers | wc -l"  |      //read number of process with this name
read x 
if [ $x = 7 ]; then                                          //compare with 7
echo "WARNING SOME WORKER DONT WORK"
else
echo "ALL WORKERS WORKING"   
fi
echo `ps -C GFN22 --no-headers | wc -l`  |awk '{print "PERCENTAGE OF PROCESS " $1*100/7 " % "}'
But this doesnot work

if I echo "ps -C GFN22 --no-headers | wc -l" > x then x contain 7 : since 7 GPU run GFN22 process
But script doesnot compare , since I can change anything and still showing all worker is running.
I try $x and "$x" and some write Debian has own bash.....
What I do wrong?
pepi37 is offline   Reply With Quote
Old 2022-10-17, 23:38   #2
retina
Undefined
 
retina's Avatar
 
"The unspeakable one"
Jun 2006
My evil lair

3×17×131 Posts
Default

Using normal quotes with echo: echo "ps -C GFN22 --no-headers | wc -l"

Elide the read x and try this x=$(ps -C GFN22 --no-headers | wc -l)
retina is offline   Reply With Quote
Old 2022-10-17, 23:49   #3
pepi37
 
pepi37's Avatar
 
Dec 2011
After milion nines:)

31278 Posts
Default

Quote:
Originally Posted by retina View Post
Using normal quotes with echo: echo "ps -C GFN22 --no-headers | wc -l"

Elide the read x and try this x=$(ps -C GFN22 --no-headers | wc -l)

If I use normal quotes then command give me incorrect result. ( both are same: in first I use " in last line I use ` )


x=$(ps -C GFN22 --no-headers | wc -l) doesnot work still wrong result.

Last fiddled with by pepi37 on 2022-10-17 at 23:51
pepi37 is offline   Reply With Quote
Old 2022-10-17, 23:58   #4
retina
Undefined
 
retina's Avatar
 
"The unspeakable one"
Jun 2006
My evil lair

3×17×131 Posts
Default

It seems weird to me that when x=7 you say some not working, but any other number means all working.
retina is offline   Reply With Quote
Old 2022-10-18, 00:01   #5
slandrum
 
Jan 2021
California

11·47 Posts
Default

Quote:
Originally Posted by pepi37 View Post
Code:
if [ $x = 7 ]; then                                          //compare with 7
echo "WARNING SOME WORKER DONT WORK"
else
echo "ALL WORKERS WORKING"   
fi
So if X is 7, you are wanting to print that some workers are not working, but if x is NOT 7 then all the workers are? I think you have it flipped.

ETA: retina got in their response while I was staring at this.

Last fiddled with by slandrum on 2022-10-18 at 00:03
slandrum is offline   Reply With Quote
Old 2022-10-18, 02:10   #6
EdH
 
EdH's Avatar
 
"Ed Hall"
Dec 2009
Adirondack Mtns

24·3·109 Posts
Default

Not sure, but don't forget = and == are different. You need == to compare.
EdH is offline   Reply With Quote
Old 2022-10-18, 02:42   #7
retina
Undefined
 
retina's Avatar
 
"The unspeakable one"
Jun 2006
My evil lair

3·17·131 Posts
Default

Quote:
Originally Posted by EdH View Post
Not sure, but don't forget = and == are different. You need == to compare.
For the [ is makes no difference AFAICT.
Code:
~  if [ 7 == 7 ] ; then echo y ; fi
y
~  if [ 6 == 7 ] ; then echo y ; fi
~  if [ 7 = 7 ] ; then echo y ; fi
y
~  if [ 6 = 7 ] ; then echo y ; fi
~
retina is offline   Reply With Quote
Old 2022-10-18, 03:00   #8
EdH
 
EdH's Avatar
 
"Ed Hall"
Dec 2009
Adirondack Mtns

121608 Posts
Default

Hence, the "Not sure."

Another thought - what if you use "< 8" rather than "= 7" in your test?
EdH is offline   Reply With Quote
Old 2022-10-18, 10:17   #9
pepi37
 
pepi37's Avatar
 
Dec 2011
After milion nines:)

3·541 Posts
Default

Quote:
Originally Posted by slandrum View Post
So if X is 7, you are wanting to print that some workers are not working, but if x is NOT 7 then all the workers are? I think you have it flipped.

ETA: retina got in their response while I was staring at this.

echo "STATUS GFN PROCESS"
x=$( echo `ps -C GFN22 --no-headers | wc -l` )
if [ x = 6 ]; then
echo "ALL WORKERS WORKING"
else
echo "ALL WORKERS NOT WORKING"
fi



I can change x = 6 or x = 7 and will get again wrong answer: so script doesnot compare number 7 ( as result) with if then statement. In this case x is compared to 6 and since it is 7 all workers not working is correct answer, But if I change to x = 7 then again got same answer: all workers is not working. So for that I know script doesnot compare well .

Last fiddled with by pepi37 on 2022-10-18 at 10:17
pepi37 is offline   Reply With Quote
Old 2022-10-18, 10:24   #10
retina
Undefined
 
retina's Avatar
 
"The unspeakable one"
Jun 2006
My evil lair

3×17×131 Posts
Default

Quote:
Originally Posted by pepi37 View Post
...
if [ x = 6 ]; then ....
if [ $x = 6 ] ...
retina is offline   Reply With Quote
Old 2022-10-18, 10:30   #11
pepi37
 
pepi37's Avatar
 
Dec 2011
After milion nines:)

3·541 Posts
Default

Quote:
Originally Posted by retina View Post
if [ $x = 6 ] ...
I looks like I need big glasses!
Thanks Retina !
pepi37 is offline   Reply With Quote
Reply

Thread Tools


All times are UTC. The time now is 15:32.


Wed Feb 1 15:32:14 UTC 2023 up 167 days, 13 hrs, 1 user, load averages: 0.89, 1.09, 1.08

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2023, Jelsoft Enterprises Ltd.

This forum has received and complied with 0 (zero) government requests for information.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
A copy of the license is included in the FAQ.

≠ ± ∓ ÷ × · − √ ‰ ⊗ ⊕ ⊖ ⊘ ⊙ ≤ ≥ ≦ ≧ ≨ ≩ ≺ ≻ ≼ ≽ ⊏ ⊐ ⊑ ⊒ ² ³ °
∠ ∟ ° ≅ ~ ‖ ⟂ ⫛
≡ ≜ ≈ ∝ ∞ ≪ ≫ ⌊⌋ ⌈⌉ ∘ ∏ ∐ ∑ ∧ ∨ ∩ ∪ ⨀ ⊕ ⊗ 𝖕 𝖖 𝖗 ⊲ ⊳
∅ ∖ ∁ ↦ ↣ ∩ ∪ ⊆ ⊂ ⊄ ⊊ ⊇ ⊃ ⊅ ⊋ ⊖ ∈ ∉ ∋ ∌ ℕ ℤ ℚ ℝ ℂ ℵ ℶ ℷ ℸ 𝓟
¬ ∨ ∧ ⊕ → ← ⇒ ⇐ ⇔ ∀ ∃ ∄ ∴ ∵ ⊤ ⊥ ⊢ ⊨ ⫤ ⊣ … ⋯ ⋮ ⋰ ⋱
∫ ∬ ∭ ∮ ∯ ∰ ∇ ∆ δ ∂ ℱ ℒ ℓ
𝛢𝛼 𝛣𝛽 𝛤𝛾 𝛥𝛿 𝛦𝜀𝜖 𝛧𝜁 𝛨𝜂 𝛩𝜃𝜗 𝛪𝜄 𝛫𝜅 𝛬𝜆 𝛭𝜇 𝛮𝜈 𝛯𝜉 𝛰𝜊 𝛱𝜋 𝛲𝜌 𝛴𝜎𝜍 𝛵𝜏 𝛶𝜐 𝛷𝜙𝜑 𝛸𝜒 𝛹𝜓 𝛺𝜔