how to use telnet in script | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

how to use telnet in script

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 06-02-2005
sibghat sibghat is offline
Registered User
 
Join Date: Jun 2005
Last Activity: 7 June 2006, 9:50 AM EDT
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
how to use telnet in script

I am trying to use telnet in shell script but getting following error

error
Connected to crmapp00.agf.ca.
Escape character is '^]'.
Connection closed by foreign host.

Script
#!/bin/ksh
PATH=/usr/sbin/:/usr/bin:/usr/ucb:/etc:/usr/local/bin:.
telnet HOSTNAME <<SCRIPT
user userid password
SCRIPT
exit

i think i am doing something wrong in this area
user userid password

Actually i have tried different way too but didn't work it prompt me for userid and password.
#!/bin/ksh
PATH=/usr/sbin/:/usr/bin:/usr/ucb:/etc:/usr/local/bin:.
telnet HOSTNAME
user userid password
exit

I'll really appreciate if someone can help me…

Thanks in Advance.
Sponsored Links
    #2  
Old 06-02-2005
reborg's Avatar
reborg reborg is offline Forum Advisor  
Administrator Emeritus
 
Join Date: Mar 2005
Last Activity: 29 March 2012, 7:00 PM EDT
Location: Ireland
Posts: 4,464
Thanks: 0
Thanked 11 Times in 11 Posts
You cannot use a here document with telnet.

If this task really must be done with telnet it could best be done with expect, otherwise use a login method which does not need interactive logins such as rsh/rexec or preferably ssh.
Sponsored Links
    #3  
Old 06-02-2005
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Advisor  
Forum Advisor
 
Join Date: Feb 2005
Last Activity: 24 October 2014, 7:17 PM EDT
Location: Foxborough, MA
Posts: 7,667
Thanks: 152
Thanked 586 Times in 551 Posts
Quote:
Originally Posted by reborg
You cannot use a here document with telnet.

If this task really must be done with telnet it could best be done with expect, otherwise use a login method which does not need interactive logins such as rsh/rexec or preferably ssh.
I second the above!
Here's the "poor-man's" inline telnet which might not be bullet-proof for all the cases:

Code:
    (
    sleep 3
    print user
    sleep 1
    print password
    sleep 2
    print "ls ~"
    sleep 1
    print "exit"
    sleep 3
    ) | telnet hostname

    #4  
Old 06-03-2005
sibghat sibghat is offline
Registered User
 
Join Date: Jun 2005
Last Activity: 7 June 2006, 9:50 AM EDT
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Thank you so much it worked
Sponsored Links
    #5  
Old 04-02-2007
mady mady is offline
Registered User
 
Join Date: Mar 2007
Last Activity: 3 April 2007, 7:43 AM EDT
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
this one is working, but it exits the telnet session at the end. i want the script to make a permanant connection to the server so that whenever i want to connect, i can just run the script instead of entering all the credinals.
Quote:
Originally Posted by vgersh99
I second the above!
Here's the "poor-man's" inline telnet which might not be bullet-proof for all the cases:

Code:
    (
    sleep 3
    print user
    sleep 1
    print password
    sleep 2
    print "ls ~"
    sleep 1
    print "exit"
    sleep 3
    ) | telnet hostname

Sponsored Links
    #6  
Old 04-02-2007
ghostdog74 ghostdog74 is offline
Registered User
 
Join Date: Sep 2006
Last Activity: 24 October 2014, 9:49 AM EDT
Posts: 2,662
Thanks: 0
Thanked 17 Times in 17 Posts
if you have Perl, you can use the Net::Telnet module. eg here
Sponsored Links
    #7  
Old 04-03-2007
mady mady is offline
Registered User
 
Join Date: Mar 2007
Last Activity: 3 April 2007, 7:43 AM EDT
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
no, i dont ve pearl. i just want a script that can connect to server using telnet and therafter it should end, but not the connection
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Telnet script Pouchie1 Shell Programming and Scripting 3 08-27-2010 06:08 AM
Telnet and ssh in a script marwan UNIX for Dummies Questions & Answers 3 06-11-2007 10:58 AM
Telnet in a script insania Shell Programming and Scripting 5 04-15-2007 01:32 PM
telnet through script arun.viswanath UNIX for Dummies Questions & Answers 1 03-26-2006 11:33 AM
ksh telnet script rwunwla Shell Programming and Scripting 5 12-16-2005 08:22 AM



All times are GMT -4. The time now is 01:35 AM.