LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Send character in sh script (https://www.linuxquestions.org/questions/linux-newbie-8/send-character-in-sh-script-725244/)

Alli 05-11-2009 12:50 PM

Send character in sh script
 
I need to send the character $ and C in a script. One the same line just the two characters separated. I have read some script how-to's but no finding what I need.

jschiwal 05-11-2009 12:53 PM

What do you mean by send?
Do you mean echo?
echo '$C'

Alli 05-11-2009 01:01 PM

Sorry, Need to send the characters. $ C
I am logged on to a scale through telnet. The script logs me in. Now to retrieve the weight on the scale it requires the $ and the C. Echo displayed the character on the screen. Is there a send command to send the characters ?

David1357 05-11-2009 03:09 PM

Quote:

Originally Posted by Alli (Post 3537286)
Is there a send command to send the characters ?

If you are using telnet, you can just type $C. The characters will not echo (unless you have modified the settings of your terminal program), but they will be sent.

Alli 05-12-2009 11:02 AM

Thanks for the reply. Didn't work... Is there a way to send an input file ?

chrism01 05-12-2009 07:05 PM

Actually, once you've logged in with telnet, anything you type will be 'sent' to the remote system, so

telnet box1
username
passwd
# now you are logged in can type your chars
$
C

# or on same line
$ C

# or together
$C

we really need a a screenshot/more info to understand your issue.
To copy to remote system use scp (or rcp if scp not avail)

michaelk 05-12-2009 07:30 PM

Can you provide some more information on the scale i.e. make / model and its communication protocol? Maybe a link too.

Alli 05-13-2009 09:57 AM

Will work on getting the make and model of the scale. This is the script that I am working on.

#!/bin/sh
# Get weight off the scale!
telnet <<EOF > pound.lis
open 192.168.X.XXX # local address

$C # command to populate pound.lis with weight on scale. Doesn't get sent !

exit
EOF
cat pound.lis


This script will log me in to the scale. There is no username or password, unfortunately it will not retrieve the weight. pound.lis only shows successfully connected and the break charactors.

If I send 192.168.X.XXX | tee pound.lis and then manually type $C the weight is sent to the pound.lis file.

I would love to have this in a script. Can anyone help ?

David1357 05-13-2009 02:54 PM

Quote:

Originally Posted by Alli (Post 3539502)
Code:

#!/bin/sh
# Get weight off the scale!
telnet <<EOF > pound.lis
open 192.168.X.XXX  # local address

$C  # command to populate pound.lis with weight on scale.  Doesn't get sent !
 
exit
EOF
cat pound.lis


Your script is busted. From the man page for bash in the "Here Documents" section:

Code:

If word is unquoted, all lines of the here-document are
subjected to parameter expansion, command substitution,
and arithmetic expansion.

The shell is interpreting "$C" as a variable. It is, of course, set to nothing, so nothing gets sent. Luckily, the man page tells you how to solve your problem:

Code:

In the latter case, the character sequence \<newline> is
ignored, and \ must be used to quote the characters \,
$, and '.

So you can fix your script by changing "$C" to "\$C".


All times are GMT -5. The time now is 08:43 PM.