LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 03-22-2010, 08:51 PM   #1
i_have_a_question
LQ Newbie
 
Registered: Mar 2010
Posts: 6

Rep: Reputation: 0
Unhappy "write" bash command


Hello, I'm trying to write a bash script program in the Linux command terminal that will write to a fellow user and then continue reading down the program. this is what i have (kind of explains the idea too):

#!/bin/sh

clear
echo "this is before the write command"
write jcummins
this message should go to jerry
echo "the message didn't send and this string will not appear"
echo "it appears it has stopped at the write command"

please help me,
THANK YOU!
 
Old 03-22-2010, 09:18 PM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,000

Rep: Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190
Well I cannot say I have used this command, but I did find the following:

Quote:
Since write is interactive, it would not normally find use in a script.
 
Old 03-22-2010, 09:32 PM   #3
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 555Reputation: 555Reputation: 555Reputation: 555Reputation: 555Reputation: 555
I had never heard of the write command until this thread. But I figure, since other interactive stuff occurs in scripts, then why not? Though it really doesn't appear to need a script to be used, as it's kind of a one-shot deal:

Code:
sasha@reactor: w
 23:43:54 up 18:58,  2 users,  load average: 0.12, 0.08, 0.08
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
sasha    tty2     -                04:47   18:54m 15:08   0.00s /bin/sh /usr/bin/startx
sasha    pts/0    :0.0             23:38    0.00s  0.21s  0.06s /usr/bin/xterm -fn -misc-Fixed-Med
sasha@reactor: write sasha /dev/pts/0 << EOF
> jellooo
> EOF
causes this in my xterm:
Code:
Message from sasha@reactor on pts/0 at 23:44 ...
jellooo
EOF
sasha@reactor:
It appears to work assuming you know which console a user is logged in on (try the `w` command to see).

Sasha
 
Old 03-23-2010, 07:18 AM   #4
i_have_a_question
LQ Newbie
 
Registered: Mar 2010
Posts: 6

Original Poster
Rep: Reputation: 0
THANK YOU! you are amazing!
 
Old 03-23-2010, 08:54 PM   #5
i_have_a_question
LQ Newbie
 
Registered: Mar 2010
Posts: 6

Original Poster
Rep: Reputation: 0
When I add a loop the program should send the message, "Hello Jerry!!" 5 times to jerry's terminal(assuming he is logged on to the server). But I keep getting this error: Syntax error: end of file unexpected (expecting "done")

I have tried everything and searched everywhere to find a solution and nothing has worked
any ideas? Thanks!


-----------------------------------------------------------------------

#!/usr/bin/sh

clear

x=1 # this sets up the flag so we can have it send a limited amount

while [ $x -le 5 ]
do
write jcummins << EFO
>Hello Jerry!!
>EFO
x=$(( $x + 1 ))
done
 
Old 03-23-2010, 09:45 PM   #6
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 555Reputation: 555Reputation: 555Reputation: 555Reputation: 555Reputation: 555
If that is the EXACT code that is in your script, then the problem is likely those ">" characters.

If you copied the code from my above example, then you should know that I just did that right in my console; this makes bash print the > character on the next line when it is waiting for more input.

Other than those > characters, I don't see a problem with your code (other than that you have not specified which tty or pty jerry might be logged into).

Also, for the record, EFO is usually "EOF" which stands for "End Of File", though if you like to use "EFO" you can certainly continue doing so; as long as the EOF and EOF at the start and end, are the same, it will work.

Sasha
 
  


Reply

Tags
command, write


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
How to write a simple BASH script to "test if have folowing files, than delete."? hocheetiong Programming 10 10-01-2009 12:17 PM
Standard commands give "-bash: open: command not found" even in "su -" and "su root" mibo12 Linux - General 4 11-11-2007 10:18 PM
How to write a bash script to replace all "KH" to "K" in file ABC??? cqmyg5 Slackware 4 07-24-2007 09:00 AM
Use bash to interface with "write" command? jon_k Linux - General 3 10-31-2006 04:48 AM
Bash: "after" or "waitfor" command enemorales Programming 3 06-15-2005 12:04 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:41 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration