broken pipe error


 
Thread Tools Search this Thread
# 1  
telnet using a script - broken pipe error

I'm new to scripting, and this forum has been invaluable in helping me out. I'm hoping I can get some personal help now though.

I have a korn script that takes a list of servers and either telnets or sshs into it (only some are set up for ssh). What I'm doing now is trying to telnet first, and if it doesn't work then I ssh. The problem is I get a broken pipe error if ssh is needed. The script still works fine, but people will be freaking out over the broken pipe. Is there a way to prevent the broken pipe error from showing, or a different way to check if the server should be telnet or ssh?

My current code:

Code:
(sleep 1
print <username>
sleep 1
print <password>
sleep 1
print "<some command I need output from>"
sleep 1
print "logout"
) | telnet server1 > $temp_file 2>/dev/null
 
if [ $? -ne 0 ]; then
    <code to ssh into server>
fi

I tried to build a file and do telnet < login_file but I couldn't get that work. I probably did that wrong though. Does anyone know how I'd build the file to redirect to the telnet command?

TIA!

Last edited by aimeet; 03-12-2012 at 09:19 PM.. Reason: please use code tags
# 2  
Though I am amazed that this code works:

Maybe try appending this redirect of STDERR to the command which produces the error:
Code:
2>/dev/null

# 3  
Quote:
Originally Posted by methyl
Though I am amazed that this code works:

Maybe try appending this redirect of STDERR to the command which produces the error:
Code:
2>/dev/null

I edited my code. I actually already tried redirecting the STDERR.

Is the code that bad? Smilie I was basing it off of current scripts we have, which is how I even knew how to do the telnet in the first place....
# 4  
That kind of thing is usually inside a here doc: the EOF marks the "boundaries", last boundary goes in column 1 - leftmost column. The other are not sensitive to columns.
Code:
telnet remotenode << EOF
username
password
command goes here
exit
EOF

# 5  
process pipes are not files, they are memory objects and so are process persistent. That means they go away when the "reader" process ends - and when it ends too soon you get broken pipe errors. The reader is on | <right side> of the pipe.
The error you got was caused the the reader, telnet, exiting before the child process that was feeding data was finished. -- the part inside the ( )
# 6  
Quote:
Originally Posted by jim mcnamara
That kind of thing is usually inside a here doc: the EOF marks the "boundaries", last boundary goes in column 1 - leftmost column. The other are not sensitive to columns.
Code:
telnet remotenode << EOF
username
password
command goes here
exit
EOF

Thanks so much, I will try this tomorrow. Would I be able to get the output of the command executed during the telnet session into a file?
# 7  
Quote:
telnet remotenode << EOF
username
password
command goes here
exit
EOF
This will not work because typeahead is not allowed for the username and password in telnet.

The original script in post #1 does work when all parameters are correct, with the exception of logout which should be exit .
Surely Remote Shell would be easier to work with - and that too can be configured for automatic login.
 

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How can we overcome Broken pipe error during scp,SFTP,Rsync while transferring big files.?

Hello All, Hope all are doing well. We use scp (some times sftp and rsync also) for transferring big files (around 2GB each ) from 1 Network to another Network. The Issues which we face :- During transfer some times( Once in 1 week (or twice)) , the speed of transfer gets down to 30 kb/s,... (2 Replies)
Discussion started by: Upendra Bhushan
2 Replies

2. Solaris

RWSocket::send: Broken pipe Error in /var/adm/messages

Hi Guys, I am getting some strange error in /var/adm/messages in my Solaris 10 box with Veritas Cluster and EMC storage. bash-3.00$ cat /var/adm/messages | egrep -v "lw8|snmp|sshd|xntpd|kern.info|LOGIN|link|service|started|finished|repeated|SS7 Log-daemon|success" Dec 18 09:58:35 GAMMa2... (1 Reply)
Discussion started by: vivek.goel.piet
1 Replies

3. UNIX for Dummies Questions & Answers

SFTP error between UNIX to iSeries (Write Failed Broken Pipe)

Hi, I am iseries resource and having Issue in one of the sFTP failures between one of my job (Unix --> iSeries). The response to sending machine (Unix) is "Write Failed Broken Pipe". Appreciate any help Available on why this Issue happens, how can we replicate the same, what fixes can... (1 Reply)
Discussion started by: hamelchauhan
1 Replies

4. Shell Programming and Scripting

Broken Pipe error

Hello while doing sftp over server "A" , i am getting a broken pipe error i.e cat: write error: Broken pipe what does that mean? please let me know if you want any other info on this.. (3 Replies)
Discussion started by: urfrnddpk
3 Replies

5. UNIX for Advanced & Expert Users

sftp error:- Couldn't send packet: Broken pipe

Hi, I am trying to sftp a large file(appx. 2 GB size) from solaris 10 to a Linux server. While sftping(with no options), connection is terminated after some time with broken pipe error. sftp with option -R1 or -B1500 is successful. Linux server ssh Version: OpenSSH_3.9p1, OpenSSL 0.9.7a... (3 Replies)
Discussion started by: brij123
3 Replies

6. Shell Programming and Scripting

Replace pipe with Broken Pipe

Hi All , Is there any way to replace the pipe ( | ) with the broken pipe (0xA6) in unix (1 Reply)
Discussion started by: saj
1 Replies

7. UNIX for Dummies Questions & Answers

echo: write error: Broken pipe ??

I want to try the unix pipe, the command is like this: echo new | find . the standard output of the echo should be "new", then I guess find command will use this output as input to find the file named "new". But the output is all the file names in my current dir, the last line is "echo: write... (5 Replies)
Discussion started by: andrewust
5 Replies

8. Programming

Broken Pipe error

All, I am using the below code The C code : if ((fp2=fopen(szout_fname,"r"))==NULL) { sprintf(stream_ptr1,"cat %s | sort -t, -rn -k 11,11 | awk -F\",\" '{ \ if ( \$3 ==\"%s\" ) {print... (0 Replies)
Discussion started by: arunkumar_mca
0 Replies

9. AIX

broken pipe error

Hi, I am working on AIX 5.3 . I have client-server program which is in ProC.while sending packet to server i am getting error as broken pipe and program exiting. please help?/? (1 Reply)
Discussion started by: ajaysahoo
1 Replies

10. UNIX for Dummies Questions & Answers

broken pipe

sometimes I ftp files from an Unix environment from the command prompt of my win2000 pc and I get a "broken pipe" message. sometimes I'll get nothing but sometimes I'll get part of the file. Whats this "broken pipe" about?? (3 Replies)
Discussion started by: eloquent99
3 Replies

Featured Tech Videos