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! |
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? |
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.
|
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").
|
okay that makes sense...how would you terminate on reading "End of File" in the script?
|
#!/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! |
I figured it out...thanks again guys!
|
All times are GMT -5. The time now is 11:38 PM. |