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

  Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

how to use telnet in script

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 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 Unix and Linux 06-02-2005
reborg's Unix or Linux Image
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 12 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 Unix and Linux 06-02-2005
vgersh99's Unix or Linux Image
vgersh99 vgersh99 is offline Forum Advisor  
Forum Advisor
 
Join Date: Feb 2005
Last Activity: 25 July 2016, 9:07 AM EDT
Location: Foxborough, MA
Posts: 7,948
Thanks: 184
Thanked 685 Times in 641 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 Unix and Linux 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 Unix and Linux 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 Unix and Linux 04-02-2007
ghostdog74 ghostdog74 is offline
Registered User
 
Join Date: Sep 2006
Last Activity: 28 January 2015, 8:30 AM EST
Posts: 2,669
Thanks: 0
Thanked 18 Times in 18 Posts
if you have Perl, you can use the Net::Telnet module. eg here
Sponsored Links
    #7  
Old Unix and Linux 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 Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux 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 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 09:57 AM.