AIX bash script - exiting freezed telnet


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers AIX bash script - exiting freezed telnet
# 1  
Old 09-14-2015
AIX bash script - exiting freezed telnet

Hallo all
I'm writing a little shellscript in aix in order to test the correct connection to a specific ip-port. I'm using the sleep|telnet combination. All works great if connection is already open.. But if telnet connection are in trying state... It doesn't exit and all the rest of the script remains un-executed. How can I send a break signal from a telnet prompt (in "trying" status), via shell-script? Thanks all For Your support

Last edited by libeccio; 09-14-2015 at 06:42 PM..
# 2  
Old 09-15-2015
Can you share your code so we can see how you have it please?


Thanks,
Robin
# 3  
Old 09-15-2015
This one works, but not for Trying state connections.

Maybe, in order to fix the 'append' state, should I have to fork telnets? Any alternatives? Thanks in advance.
Code:
echo "insert dest ip" 
read ip1
echo "insert first port of the range"
read p1
echo "insert last port of the range"
read pn
echo $ip1 >> myips.txt
echo $p1 $pn | awk '{ for (i=$1;i<=$2;i++) { print i} }'>> myports.txt
for ip in $('cat' myips.txt)
do
for port in $('cat' myports.txt)
do
echo ""
echo ""
echo "telnet $ip $port" >> result.txt
sleep 1 | telnet $ip $port >> result.txt 2>&1
echo "" >> result.txt
echo "" >> result.txt
done
echo "Done. See result.txt"" 
done


Moderator's Comments:
Mod Comment
Please wrap all code, files, input & output/errors in CODE tags.
It makes them easier to read and preserves multiple spaces for indenting or fixed width data.

Last edited by rbatte1; 09-15-2015 at 10:45 AM.. Reason: Added CODE tags
# 4  
Old 09-15-2015
A few small things first, you could save statements by using the following syntax:-
Code:
read ip1?"insert dest ip: "

You could also save the writing and then reading back the file by using a while loop:-
Code:
port=$p1
while [ $port -le $pn ]
do
   # All the logging & active stuff here
  ((port=$port+1))
done

Now, the active statement. Assuming that you want to timeout in just a few seconds, not 30 or so (if ever) then I've had some success with a background process, but I'm not sure it will work with telnet as that needs the screen to interact with. I will have a think.

Anyone else?



Robin
This User Gave Thanks to rbatte1 For This Post:
# 5  
Old 09-18-2015
Hi, I found this solution (not so 'strong' but it worked for me)... .Any Comments will be appreciated.. Thanks for your help.

Code:
#!/bin/ksh
touch myips.txt myports.txt result.txt
rm myips.txt myports.txt result.txt
read ip1?"insert dest ip: "
read p1?"insert first port of the range (or the unique one): "
read pn?"insert last port of the range (or the unique one): "
echo $ip1 >> myips.txt
echo $p1 $pn | awk '{ for (i=$1;i<=$2;i++) { print i} }'>> myports.txt
for ip in $('cat' myips.txt)
do
   for port in $('cat' myports.txt)
   do
       echo ""
       echo ""
       echo "telnet $ip $port" >> result.txt
       sleep 1 | telnet $ip $port >> result.txt 2>&1 &
       echo "Telnet in progress..saving results to "result.txt"" 
       PID=$!
       sleep 2
       if [ $(ps -efa | grep $PID |grep -v grep|grep -v defunct| wc -l) -eq 1 ]; then
          TMOUT_CONN=$(ps -efa | grep $PID |grep -v grep|grep -v defunct| awk '{print $9,$10}') 
           kill -9 $PID
           echo "PID $PID still UP after 2 seconds, connection to $TMOUT_CONN is in Trying state.\nSubprocess Killed"
       fi
   done
done

Moderator's Comments:
Mod Comment Please use code tags next time for your code and data

Last edited by vbe; 09-18-2015 at 02:41 PM.. Reason: code tags
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Telnet Bash Script (Connection closed by foreign host.)

Hello Everyone, My following script is giving me problems, when the SIP trunk goes down and the telnet session is started and just when the command is about to complete the connection is closed then script restarts. I have noticed that as soon the script types in "sys re" or "sys rebo" or... (6 Replies)
Discussion started by: jeetz
6 Replies

2. AIX

Help migrating bash script to AIX machine

hey frnds I am trying to migrate a bash script over the AIX machine , but was getting error with ps and read commands, so I make the few changes in script and have also chnaged the shell from bash to ksh below is my script... (5 Replies)
Discussion started by: sumit_saxena
5 Replies

3. AIX

How to kill exiting process in AIX

I could not able to kill two process which is running in the required port for me.Can any body help me to kill the exiting process. - 27000908 - - - <exiting> - 30998528 - - - <exiting> (8 Replies)
Discussion started by: sasikanta
8 Replies

4. Shell Programming and Scripting

Exiting out of the script

I have to write a script in ksh which again should call another script. Say A.ksh is calling B.ksh. Now in B.ksh if the condition we are checking for is true then we have to go back to the main script A.ksh or if the condition in B.ksh is false then we have to totally come out of the scripts. I... (1 Reply)
Discussion started by: vpv0002
1 Replies

5. Shell Programming and Scripting

Bash Script Not Exiting

I have a script planned for the Helpdesk to allow them to (on a couple of RHEL 3 / RHEL 5 servers) reset passwords, stop / start printers, and clear print queues. The appropriate sudo permissions were given to their accounts, and the individual functions all work just fine. The ability to move... (0 Replies)
Discussion started by: tearsong
0 Replies

6. AIX

telnet script problem from DOS to AIX

hello, i made a script with a telnet scripting tool, tst10.exe, the problem is that when i put the commands send "rlogin aix57\m" wait "password:" send "op_syst.\m" wait "$" it do the login but a menu appears where you have to choose a terminal type, you have 8 options, 8 types of... (1 Reply)
Discussion started by: pabloli150
1 Replies

7. Shell Programming and Scripting

exiting from script

Hi, I am trying to exit the script from a function. I was in assumption that if we use exit ( inside or outside the function) it will exit from the script. alternatively, return will exit from that particular function. but in my case, exit is exiting from the function and not the script.... (8 Replies)
Discussion started by: shellwell
8 Replies

8. Shell Programming and Scripting

Exiting a script

I have a script abc.sh. Its contents are as follows: (7 Replies)
Discussion started by: lassimanji
7 Replies

9. Shell Programming and Scripting

exiting from script

there are many script in my project.i am having a problem when i am trying to quit from child script.what is the command to wrap up all the parent script and calling script as well? exit 0 is not working.please help.... (1 Reply)
Discussion started by: arghya_owen
1 Replies

10. Shell Programming and Scripting

Bash: Exiting while true loop when terminal is not the focus window

I am running an Ubuntu Gutsy laptop with Advanced Compiz fusion options enabled. I am using xdotool to simulate keyboard input in order to rotate through multiple desktops. I am looking for a way to kill a while true loop when the Enter key (or Control+C if it is easier) is pushed when the... (2 Replies)
Discussion started by: acclaypool
2 Replies
Login or Register to Ask a Question

Featured Tech Videos