If Telnet fail abort other command..??


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting If Telnet fail abort other command..??
# 1  
Old 03-31-2015
If Telnet fail abort other command..??

Hi Team,
I my script i telent my node ip and after loging i run some commands...But some time login fail so i want to stop script at that time..


CONFIG_CHNG.sh
Code:
printf 'Please Input Node ID : '
read node
node="$node"
 
#exec > node_log_$node.log 2>&1
#set -x
> node_log_$node.log
IP=`cmd_sys Node_$node ======= | grep -i ".111" | awk '{print$3}'`
port=`cmd_sys Node_$node ========== | grep -i ".333" | awk '{print$2}' | cut -c 3- | rev | cut -c 5- | rev`

NEWIP="$IP"

string1="setenv -p PORT"$port"_IPV_GW"
string2="setenv -p PORT"$port"_IPV_IP"
echo ":"
echo ":"
echo ":"
echo "Given node OAMIP:     $NEWIP"
echo "Given node GWIP :     $p"
echo "BH CONCT  PORT  :      $port"
echo ":"
echo ":"
echo ":"

Nodelogin.sh $NEWIP $p $port $string1 $string2                         #Here in this script we login to Node if login fail i need to abort script here

cmd_sys $node ======:======"$port"_VLANID,ENV_VALUE=123
cmd_sys $node =======:======PORT"$port"_IPV_NM,ENV_VALUE=111
cmd_sys $node =======:======E=PORT"$port"_IPVER,ENV_VALUE=4
cmd_sys $node ======:======"$port"_VLANID,ENV_VALUE=123
cmd_sys $node =======:======PORT"$port"_IPV_NM,ENV_VALUE=111
cmd_sys $node =======:======E=PORT"$port"_IPVER,ENV_VALUE=4


Nodelogin.sh
Code:
#!/usr/bin/expect
set timeout 2
set ip [lindex $argv 0]
spawn telnet $ip
expect "login:"
send "USER\r"
expect "Password:"
send "pass_123\r"
:
:
:# Here we change some parameter
:
:
exit



Please help me....!!!!!!@@


Moderator's Comments:
Mod Comment Please use code tags not icode for whole blocks of text, thanks.


---------- Post updated at 09:54 AM ---------- Previous update was at 08:01 AM ----------

Please some one ..
Give me some idea!!!!!!

Last edited by Ganesh Mankar; 03-31-2015 at 11:52 AM.. Reason: icode to code
# 2  
Old 03-31-2015
If we don't answer immediately, wait! Nobody here is "on call".

You must alter your expect script to return a value, 0 on success, 1 on error, so that your shell script can tell if anything goes wrong. How to do this depends on your script.

Then you can do
Code:
if ! Nodelogin.sh $NEWIP $p $port $string1 $string2
then
        echo "Telnet failed" >&2
        exit 1
fi

This User Gave Thanks to Corona688 For This Post:
# 3  
Old 04-01-2015
Thanks it works...
Sorry for my inpatience
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Command after telnet

Hello, I'm trying to send a HTTP POST command after doing a telnet to a machine, like below: telnet ip port POST http://ip:port/ HTTP/1.1 Accept-Encoding: gzip,deflate Content-Type: text/xml;charset=UTF-8 SOAPAction: "test#Login" Content-Length: 200 Host: ip:port Connection:... (5 Replies)
Discussion started by: rainbow19
5 Replies

2. Shell Programming and Scripting

How to Abort or Come out of ksh script?

Hi All, I have a requirement where if Source Count is not equal to Target count, then I need to exit/abort the script and come out. Then send an email to thummi@email.com saying "RECORD COUNT DOES NOT MATCH. Please need your help. Here is what I have written : If even the count is not... (1 Reply)
Discussion started by: thummi9090
1 Replies

3. Linux

Telnet fail

Hi, I try to telnet to server: # telnet xx.xxx.1.72 1521 Trying xx.xxx.1.72... telnet: connect to address xx.xxx.1.72: Connection refused telnet: Unable to connect to remote host: Connection refused iptables is off: # service iptables status Firewall is stopped. # And I have edit... (4 Replies)
Discussion started by: mehrdad68
4 Replies

4. Shell Programming and Scripting

Banner causes scp to fail from script but not command line.

Hi, We have an interesting issue which is similar to the one in this thread, but that never provided a full answer. - Ohh apparently I can't post URLs till I have 5 posts, sorry. We have a simple script that copies files from one shelf to the other. Both shelves have an ssh banner defined. ... (3 Replies)
Discussion started by: RECrerar
3 Replies

5. Shell Programming and Scripting

tr command fail to work in script

Hi, I has the following command in the script. This command works fine if I execute on command prompt. If I run the script, this is not working as expected (deleting CR). tr -d "\015" < ${FilePath}/${FileName} > ${FilePath}/${File_Prefix}.csv I could not figure out whats... (6 Replies)
Discussion started by: kavuri
6 Replies

6. UNIX for Advanced & Expert Users

sort command abort with error

Hello, I am having an application which has been ported from UNIX. I am facing a problem with sort command. It aborts with following error message when running in a Japanese locale. sort command aborts with message "A line of the input file contains more than 20480 characters." This... (0 Replies)
Discussion started by: joshi123
0 Replies

7. Shell Programming and Scripting

Problem in checking file abort

Hi, I would like to know given executing a file with inputs, I would like to know when does it terminate /abort abnormally. I tried to append an echo $? after executing my program which is in C. However, there is nothing..It shows 0 even though the program actually exit. my command is... (1 Reply)
Discussion started by: ahjiefreak
1 Replies

8. Ubuntu

fail to telnet localhost 106

Hi folks, Ubuntu 7.04 server amd64 On running; $ telnet localhost 106 Trying 127.0.0.1... telnet: Unable to connect to remote host: Connection refused $ netstat -an | grep 106 $ sudo netstat -an | grep 106 both no printout Pls advise where shall I check and how to fix... (22 Replies)
Discussion started by: satimis
22 Replies

9. Filesystems, Disks and Memory

Abort core dumped!!!!

HI All, I am working on Solaris 8, i have this application runing on one of the partitions,(the installation was done here ie /export/home) And the out put of this goes to another parition of other disk attached to the same machine. After a certain period of time is get this error stating... (2 Replies)
Discussion started by: zing
2 Replies
Login or Register to Ask a Question