»
 

Go Back   ResellerRatings Store Ratings > ResellerRatings Forums > Tech Support

Reply
 
LinkBack Thread Tools Display Modes
Old 11-10-2003, 04:34 PM   #1 (permalink)
Registered User
 
Join Date: Aug 2002
Location: Meeshigan
Posts: 597
Ruler2112 is on a distinguished road
Another Script Variable Question

I'm having a problem reading variables with the read command from within a script. This script is being fired from xinetd in response to connections being made on a specific port number. In the script, I have the following:

Code:
echo "U"
read username
echo "-$username-" > /dev/tty2

echo "P"
read password
echo "-$password-" > /dev/tty2

echo "M"
read machinename
echo "-$machinename- > /dev/tty2
I have the second echo in there to see exactly what is in the variables. Now I can write over the network from windoze in a program written in C++ using something such as this:

Code:
char datatoSend[256];
//Read in variable via dialog box
proxyData[strlen(datatoSend)] = '\n';
proxyData[strlen(datatoSend) + 1] = '\0';
WriteExact(datatoSend, strlen(datatoSend));

//WriteExact (not written by me) snippet
//Does the socket locking here
while (i < bytes) {
  j = send(m_sock, buf+i, bytes-i, 0);
  //Error checking here
  i+=j;
  }
Writing from windoze to the script works perfectly doing this. However, if I telnet from another linux box or from windoze on this port, the variables are read, but the end is screwed up. The first hypen will echo, then the contents of the variable, but the cursor will reset to the beginning of that line before the second hyphen echos. I'm hypothesizing that some unprintable character is embedded in the variable. Why this doesn't happen from windoze is beyond me, but I would very much like it to work with both. (At least from a C++ app on win and from a shell on linux.) Is there a command to strip out all unprintable characters from within a variable?

__________________
About 5% of the people in the world can't think.
Another 5% can think and do.
The remaining 90% can think, but don't.
Ruler2112 is offline   Reply With Quote
Old 11-10-2003, 05:50 PM   #2 (permalink)
Registered User
 
SpookyEddy's Avatar
 
Join Date: Oct 2001
Location: UK
Posts: 3,125
SpookyEddy is on a distinguished road
Sounds like your variable has a trailing newline (\n) or something similar.

Unless you have a really good reason for using a shell script I would strongly suggest looking at a more powerful language such as Ruby, Python or Perl.

Is the shell script actually reading in from a socket?

What exactly are you attempting to achieve with the script?

Thanks

ed
SpookyEddy is offline   Reply With Quote
Old 11-12-2003, 12:46 PM   #3 (permalink)
Registered User
 
Join Date: Aug 2002
Location: Meeshigan
Posts: 597
Ruler2112 is on a distinguished road
That's exactly what I was thinking Eddy, but have no way to prove or disprove that theory, nor do I know of a way to strip out all the unprintable characters from a variable.

What I'm trying to do is make a script to act as a proxy server for an application. Read in the username and password in response to prompts (so the application knows what to send at what time), then the machine name. The script then executes a command (netcat) to redirect all the traffic coming in to the appropriate machine on the network. This way, I need a single port open on the firewall coming into a linux box instead of one for each machine that needs to be accessed. (A *lot* more secure and considerably less expensive.)

I have xinetd set up to listen on a specific port (the one that is going to be forwarded through the firewall of our ISP) and set to execute the script when a connection is made. I don't know if this answers your question if the script is reading from a socket or not. (I've not ever done anything like this before.)
__________________
About 5% of the people in the world can't think.
Another 5% can think and do.
The remaining 90% can think, but don't.
Ruler2112 is offline   Reply With Quote
Reply




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Most Active Discussions

Recent Discussions

All times are GMT -6. The time now is 02:49 PM.