Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How To Carriage Return With Echo and TPIPE 1

Status
Not open for further replies.

beaster

Technical User
Aug 20, 2001
225
US
I need to automate logging into a machine and sending a few commands. But I am having issues with getting it to send a carrige return after the items in quotes after echo. Can someone help me out with it?

What I have so far is below:

#!/bin/sh
tpipe()
{
sleep 3
echo -e "username" #REPLACE userid WITH YOUR USERID
sleep 1
echo "pass" #REPLACE password WITH YOUR PASSWORD
sleep 1
echo "allip;" #THE COMMAND YOU WANT TO EXECUTE GOES HERE
sleep 1
echo "exit" #LOG OFF TELNET SESSION
sleep 5
}
tpipe|telnet 10.10.10.10
 
This is Korn shell, but this seems to work for me...
[tt]
#!/bin/ksh

(
sleep 3
print "username"
sleep 1
print "password"
sleep 2
print "command"
sleep 1
print "exit"
sleep 3
) | telnet 10.10.10.10
[/tt]
I tested this on Sun Solaris using the Korn shell.

It would be cleaner and more secure (no hard coded passwords) if you used [tt]rsh[/tt] to do this. You'd just need a correct [tt].rhosts[/tt] file on the other side, then you could do the following...
[tt]
rsh 10.10.10.10 -l username command
[/tt]
Hope this helps.

 
Thanks, I will try it on the box tommorrow. It is a Sun Solaris box also!

By the way, can I redirect/output the result of the command I enter to a text file locally on the box? Not on the remote machine?

If so, how?

Thanks for the assistance.
 
Also, there is really no type of file system on the other side. It is an Ericsson BSC that allows TCP/IP connections to run commands remotely. That is why I cannot use rsh.
 
I tried the suggestion from SamBones and it still performs exactly the way I have it previously. It does not send a carriage return.

Each item in quotes should be followed by a carriage return. Thus prompting the node to return with the next input request. Basically it is just logging into an Ericsson BSC via TCP/IP.

Please look over and provide additional assistance.

Thanks,
Beaster
 
Thanks for the help. I solved it with my original post. It now looks like (also saves output file):

/usr/bin/sh test.sh > allip.txt

#!/bin/sh
tpipe()
{
sleep 3
echo "username\r"
sleep 1
echo "pass\r"
sleep 1
echo "allip;\r"
sleep 1
echo "exit\r"
sleep 5
}
tpipe|telnet 10.10.10.10
 
I have been using this without problem for almost over a week now.

The issue I am just now having is after the command allip;

Sometimes the output takes longer than 1 second. Is there a way using the above small script to not move to the next input/command until the output is completed?

Thanks for the great help always!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top