Unable to close telnet session from script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Unable to close telnet session from script
# 1  
Old 02-28-2011
Unable to close telnet session from script

Hello people, I am creating a script that will alert me in an ftp or telnet account on my system expires. FTP part is ok, but when I am entering the 3 script, it stucks. I can see that the script will not close the telnet seession. Can you please check and let me know what I am doing wrong? What if I send a CTRL-C in the script, will it work for the telnet sessin?

Code:
!/bin/sh
bill=bill@gmail.com
LOGS=/home/bill/scripts_logs
SCRIPTS=/home/bill/scripts

${SCRIPTS}/bill_ftp_check.sh > ${LOGS}/bill_ftp_check.log 2>&1
${SCRIPTS}/bill2_ftp_check.sh > ${LOGS}/bill2_ftp_check.log 2>&1
${SCRIPTS}/bill3_check.sh > ${LOGS}/bill3_check.log 2>&1
${SCRIPTS}/bill_check.sh > ${LOGS}/bill4.log 2>&1

grep failed ${LOGS}/bill_ftp_check.log
if [ $? -eq 0 ]
   then
   mailx -s "bill_ftp account expired" $bill < ${LOGS}/bill_ftp_check.log
fi

grep failed ${LOGS}/bill2_ftp_check.log
if [ $? -eq 0 ]
   then
   mailx -s "bill2_ftp account expired" $bill < ${LOGS}/bill2_ftp_check.log
fi

grep "Your password will expire" ${LOGS}/bill3_check.log
if [ $? -eq 0 ]
   then
   mailx -s "bill3 account is about to expire" $bill < ${LOGS}/bill3_check.log
fi

grep "Your password will expire" ${LOGS}/bill4_check.log
if [ $? -eq 0 ]
   then
   mailx -s "bill4 account is about to expire" $bill < ${LOGS}/bill4_check.log
fi

sleep 5

rm ${LOGS}/bill_ftp_check.log
rm ${LOGS}/bill2_ftp_check.log
rm ${LOGS}/bill2_check.log
rm ${LOGS}/bill4_check.log

exit

WHERE bill3_check.sh

Code:
#!/bin/sh

(echo open 10.0.0.10
sleep 2
echo bill3
sleep 2
echo billpass
sleep 2
echo close) | telnet

exit

Thank you in advance !

---------- Post updated at 04:57 PM ---------- Previous update was at 12:08 PM ----------

Anyone ?

Smilie
# 2  
Old 03-01-2011
Replace "close" with "exit" and it should work, given that no errors while occur.

After the open command, which is processed by telnet, you are connected to the remote computer. You send username and password which should bring you to a shell, which can be closed by the "exit" command.
This User Gave Thanks to hergp For This Post:
# 3  
Old 03-01-2011
I tried exit close quit
Same result Smilie
# 4  
Old 03-01-2011
Can you post the complete output of what happens when you call your script? Something seems to go wrong during connect or login.
This User Gave Thanks to hergp For This Post:
# 5  
Old 03-01-2011
See what's happenning if I ran telent script only:

grx666 gpd /home/bill3/scripts:./bill3_check.sh
telnet> Trying...
Connected to 10.0.0.1.
Escape character is '^]'.
Local flow control on
Telnet TERMINAL-SPEED option ON

HP-UX grx666 B.11.11 U 9000/800 (ta)

login: bil3
Password:
Last successful login for bil3: Tue Mar 1 11:17:57 EET-2EETDST 2011 on pts/ta
Last unsuccessful login for bil3: Mon Feb 14 14:47:21 EET-2EETDST 2011
Please wait...checking for disk quotas
(c)Copyright 1983-2000 Hewlett-Packard Co., All Rights Reserved.
(c)Copyright 1979, 1980, 1983, 1985-1993 The Regents of the Univ. of California
(c)Copyright 1980, 1984, 1986 Novell, Inc.
(c)Copyright 1986-1992 Sun Microsystems, Inc.
(c)Copyright 1985, 1986, 1988 Massachusetts Institute of Technology
(c)Copyright 1989-1993 The Open Software Foundation, Inc.
(c)Copyright 1986 Digital Equipment Corp.
(c)Copyright 1990 Motorola, Inc.
(c)Copyright 1990, 1991, 1992 Cornell University
(c)Copyright 1989-1991 The University of Maryland
(c)Copyright 1988 Carnegie Mellon University
(c)Copyright 1991-2000 Mentat Inc.
(c)Copyright 1996 Morning Star Technologies, Inc.
(c)Copyright 1996 Progressive Systems, Inc.
(c)Copyright 1991-2000 Isogon Corporation, All Rights Reserved.


RESTRICTED RIGHTS LEGEND
Use, duplication, or disclosure by the U.S. Government is subject to
restrictions as set forth in sub-paragraph (c)(1)(ii) of the Rights in
Technical Data and Computer Software clause in DFARS 252.227-7013.

Hewlett-Packard Company
3000 Hanover Street
Palo Alto, CA 94304 U.S.A.

Rights for non-DOD U.S. Government Departments and Agencies are as set
forth in FAR 52.227-19(c)(1,2).
HP-UX grx666 B.11.11 U 9000/800 3016405088 unlimited-user license SCM Prod
resize: unknown character, exiting.
$
(IT APPEARS SCRIPT HAS EXIT BUT I PRESS ENTER IT KEEPS CHANGING LINES)



(HERE I PRESSED CTRL-C)
telnet> Connection closed.
grx666 test /home/bill3/scripts:
(NOW IT HAS EXITED)
# 6  
Old 03-01-2011
Ah, I think I found the source of the problem:
Code:
resize: unknown character, exiting.

Your login script runs the "resize" command. It finds out the terminal's geometry by sending an escape sequence to the terminal and parsing the response. Instead of the response it reads the "exit" command, which is not understood by "resize".

Can you comment out the resize command and try again?
This User Gave Thanks to hergp For This Post:
# 7  
Old 03-01-2011
I ll do that as soon as I found what the resize does. (It's a prod system).

Thanks for your help ! Smilie

---------- Post updated at 12:11 PM ---------- Previous update was at 11:52 AM ----------

Is there any way to to use this script and leave the resize in my .profile?

How can I send a CTRL-D inside the script ?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to break out of hung or waiting telnet session in shell script?

I have to put together telnet instructions for 100s of hosts for verifying basic connectivity and get output in a neat format. Problem- If a telnet is hung with message "Trying .... <hostname" due to firewall or routing issue the commands waits for a very long time before it times out and my... (2 Replies)
Discussion started by: desiphantom
2 Replies

2. Shell Programming and Scripting

Work with setsid to open a session and close it correctly

I would like to create the following script: run a python script with setsid python may or may not fail with exception check if all of the group processes were terminated correctly if not, kill the remaining processes How can I do that? Thanks a lot (3 Replies)
Discussion started by: ASF Studio
3 Replies

3. Shell Programming and Scripting

Expect script to automate telnet session

Hi all, I am currently running a daemon which creates a virtual terminal for testing purposes. Essentially, if I were to interact with it manually, this is what I get. john@test1:~$telnet localhost 7777 Trying ::1... Connected to localhost. Escape character is '^]' mip6d> pl eth2... (6 Replies)
Discussion started by: abxccd
6 Replies

4. HP-UX

ssh session getting hung (smilar to hpux telnet session is getting hung after about 15 minutes)

Our network administrators implemented some sort of check to kill idle sessions and now burden is on us to run some sort of keep alive. Client based keep alive doesn't do a very good job. I have same issue with ssh. Does solution 2 provided above apply for ssh sessions also? (1 Reply)
Discussion started by: yoda9691
1 Replies

5. UNIX for Dummies Questions & Answers

command to close telent session when login incorrect

i need a command to close telnet session wen login incorrect..i want to embed it into my perl script for telnet to check for login incorrect error. (2 Replies)
Discussion started by: raksha.s
2 Replies

6. Shell Programming and Scripting

closing a telnet session on error, in a shell script

I am using a shell script to telnet into a remote unix server and execute certain commands. But if any command being executed remotely, throws an error, the script just hangs. And the telnet session does not get closed. I want to be able to close the session and complete the script execution in... (1 Reply)
Discussion started by: farahzaiba
1 Replies

7. Shell Programming and Scripting

How to close TELNET Connection

Hi, I have logged into a system using Telnet and iam unable to close the connection to connect to the next system using arrays. Iam getting error "Connection Timed Out" Iam using net::Telnet module. Please suggest.. (1 Reply)
Discussion started by: sudhakaryadav
1 Replies

8. Shell Programming and Scripting

Telnet Session

{ sleep 2 echo "$user" sleep 2 echo "$password" sleep 2 echo " ls" sleep 10 echo "exit" }| telnet $server I have a machine x and i have executed the above script on machine 'x'. i entered the... (6 Replies)
Discussion started by: pathanjalireddy
6 Replies

9. UNIX for Dummies Questions & Answers

telnet session timeout

hi, we can set something such that if the user has been idle for a while, it will auto disconnect. where to do so? thanks (6 Replies)
Discussion started by: yls177
6 Replies
Login or Register to Ask a Question