LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   shell scripting help! (https://www.linuxquestions.org/questions/programming-9/shell-scripting-help-803549/)

computergeek7 04-22-2010 11:26 AM

shell scripting help!
 
My question deals with me creating a name pipe (file) in the my /group directory called chat.
I then have to write a script to read from the named pipe and save data into a file called chat.log until the words End of File are passed to the program.

-When I created the named pipe file (chat) I used the mknod chat p command..Is this the correct command to create a named pipe file?

-Then I'm having trouble with my script and how to make it run until the words End of File are entered in. This is what I have so far...
#!/bin/bash


while read chat
do
chat >> chat.log
done

Thanks for the help!

David the H. 04-23-2010 12:14 AM

Is this a homework question?

mknod is for creating block and character devices, not pipes. What you want is mkfifo.

As for your second question, what's the problem exactly? Is it stopping before the end, or what?

computergeek7 04-23-2010 11:52 PM

The script is not putting any data into the chat.log file. Is it better if I use a while or until loop? I was thinking a until loop would be better since I want the script to run until the words End of File are passed to the program.But I'm not sure what would be the easiest or best way? Yes I have this for my one class I'm taking right now...I don't want you to give me the script or anything, I just wanted to get some help because I'm just getting into writing scripts..Thanks again.

catkin 04-24-2010 07:20 AM

In case the fifo does not exist or breaks, the best option is to use while read. The normal termination on reading "End of File" will have to come after the read (so you've got a line to examine) and before writing to file (because you don't want to write anything if you just read "End of File").

computergeek7 04-27-2010 10:12 AM

okay that makes sense...how would you terminate on reading "End of File" in the script?

computergeek7 04-27-2010 08:35 PM

#!/bin/bash

while read chat
do
if [[ "$chat" = 'End of File' ]]; then
break
else
chat >> chat.log
fi
done

I'm able to end the file now by typing "End of File" but I can't save the data into the chat.log file for some reason?? Any idea whys its not letting me? Thanks!

computergeek7 04-27-2010 08:50 PM

I figured it out...thanks again guys!


All times are GMT -5. The time now is 11:38 PM.