LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-11-2009, 01:50 PM   #1
Alli
LQ Newbie
 
Registered: May 2009
Location: California
Posts: 4

Rep: Reputation: 0
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.
 
Old 05-11-2009, 01:53 PM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671
What do you mean by send?
Do you mean echo?
echo '$C'
 
Old 05-11-2009, 02:01 PM   #3
Alli
LQ Newbie
 
Registered: May 2009
Location: California
Posts: 4

Original Poster
Rep: Reputation: 0
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 ?
 
Old 05-11-2009, 04:09 PM   #4
David1357
Senior Member
 
Registered: Aug 2007
Location: South Carolina, U.S.A.
Distribution: Ubuntu, Fedora Core, Red Hat, SUSE, Gentoo, DSL, coLinux, uClinux
Posts: 1,302
Blog Entries: 1

Rep: Reputation: 107Reputation: 107
Quote:
Originally Posted by Alli View Post
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.
 
Old 05-12-2009, 12:02 PM   #5
Alli
LQ Newbie
 
Registered: May 2009
Location: California
Posts: 4

Original Poster
Rep: Reputation: 0
Thanks for the reply. Didn't work... Is there a way to send an input file ?
 
Old 05-12-2009, 08:05 PM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,411

Rep: Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397
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)
 
Old 05-12-2009, 08:30 PM   #7
michaelk
Moderator
 
Registered: Aug 2002
Posts: 16,322

Rep: Reputation: 1905Reputation: 1905Reputation: 1905Reputation: 1905Reputation: 1905Reputation: 1905Reputation: 1905Reputation: 1905Reputation: 1905Reputation: 1905Reputation: 1905
Can you provide some more information on the scale i.e. make / model and its communication protocol? Maybe a link too.
 
Old 05-13-2009, 10:57 AM   #8
Alli
LQ Newbie
 
Registered: May 2009
Location: California
Posts: 4

Original Poster
Rep: Reputation: 0
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 ?

Last edited by Alli; 05-13-2009 at 10:59 AM.
 
Old 05-13-2009, 03:54 PM   #9
David1357
Senior Member
 
Registered: Aug 2007
Location: South Carolina, U.S.A.
Distribution: Ubuntu, Fedora Core, Red Hat, SUSE, Gentoo, DSL, coLinux, uClinux
Posts: 1,302
Blog Entries: 1

Rep: Reputation: 107Reputation: 107
Quote:
Originally Posted by Alli View Post
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".
 
  


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
How to send the dynamically allocated two dimensional character array through C++ UDP kbarani Linux - Software 3 05-05-2009 12:41 AM
minicom won't send a double quote character kscott121 Linux - Software 0 05-22-2008 03:34 PM
minicom - send string or single ascii character neutron001 Linux - Software 1 04-10-2008 08:08 PM
Denote ‘any character’ in script man_linux Linux - General 4 10-09-2006 04:56 PM
send automatic input to a script called by another script in bash programming jorgecab Programming 2 04-01-2004 01:20 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:46 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration