LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 04-22-2010, 11:26 AM   #1
computergeek7
LQ Newbie
 
Registered: Feb 2010
Distribution: Ubuntu
Posts: 21

Rep: Reputation: 15
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!
 
Old 04-23-2010, 12:14 AM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948
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?
 
Old 04-23-2010, 11:52 PM   #3
computergeek7
LQ Newbie
 
Registered: Feb 2010
Distribution: Ubuntu
Posts: 21

Original Poster
Rep: Reputation: 15
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.
 
Old 04-24-2010, 07:20 AM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,551
Blog Entries: 28

Rep: Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176
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").
 
Old 04-27-2010, 10:12 AM   #5
computergeek7
LQ Newbie
 
Registered: Feb 2010
Distribution: Ubuntu
Posts: 21

Original Poster
Rep: Reputation: 15
okay that makes sense...how would you terminate on reading "End of File" in the script?
 
Old 04-27-2010, 08:35 PM   #6
computergeek7
LQ Newbie
 
Registered: Feb 2010
Distribution: Ubuntu
Posts: 21

Original Poster
Rep: Reputation: 15
#!/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!
 
Old 04-27-2010, 08:50 PM   #7
computergeek7
LQ Newbie
 
Registered: Feb 2010
Distribution: Ubuntu
Posts: 21

Original Poster
Rep: Reputation: 15
I figured it out...thanks again guys!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Terminal functions for shell scripting with Shell Curses LXer Syndicated Linux News 0 03-26-2008 11:50 PM
SHELL scripting/ shell functions mayaabboud Linux - Newbie 6 12-26-2007 08:18 AM
Shell Scripting: Getting a pid and killing it via a shell script topcat Programming 15 10-28-2007 02:14 AM
teaching shell scripting: cool scripting examples? fax8 Linux - General 1 04-20-2006 04:29 AM
shell interface vs shell scripting? I'm confused jcchenz Linux - Software 1 10-26-2005 03:32 PM


All times are GMT -5. The time now is 05:56 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration