Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have writen a simple bash program. I want to run it as a background process. But it's getting stopped. I do not want that to happen. Kindly help

/#!/bin/bash  

while [ 1 ]; do  
command1 | cut -f 3  
sleep 5;  
done  

OUTPUT:  
Linux# /tmp/program &  
[19] 20162  
Linux# Line 1  
0  

[19]+ Stopped /tmp/command

Output explanation:
Line 1 and 0 are the output , and this output should be displayed every 5 secs which is what i want.
What happens: After displaying Line 1 and 0, control hangs, I press enter, I get the Stopped message. Kindly help me get rid of this.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
136 views
Welcome To Ask or Share your Answers For Others

1 Answer

the first line of your script:

/#!/bin/bash 

should actually be:

#!/bin/bash 

I assume this was just a typo when posting your question (but you might want to check that out, just in case). Now, if i replace "command1" with an ls -las, it works for me:

#!/bin/bash

while [ 1 ]; do
ls -las | cut -f 3
sleep 5;
done

notice that i've only changed your "command1" by an ls.

so what is "command1" exactly? your job may be stopped if that "command1" needs stdin input (just one of the cases)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...