- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- using telnet command in shell script
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-14-2003 03:14 AM
тАО04-14-2003 03:14 AM
using telnet command in shell script
I need to connect to remote server, automatically using cron tab in Linux . For that i would like to write a shell script.
echo `telnet
when i isuue this command , how can i supply username and password to this shell script.
Can any one please could help me in this same
above.
Thanks in Advance.
Rama
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-14-2003 04:00 AM
тАО04-14-2003 04:00 AM
Re: using telnet command in shell script
You need to use expect.
SOmething like this:
#!/usr/local/bin/expect
set username
set password
spawn telnet
expect {
-re "\[L|l\]ogin:" {
if { $mode != "PasswordSent" } {
set timeout 1
set mode SendLogin
exp_continue
}
}
-re ".*Password:" {
set timeout 1
set mode SendPassword
exp_continue
}
}
timeout {
switch $mode {
SendLogin {
send $username
send \n
exp_continue
}
SendPassword {
send $password
send \n
set timeout 5
exp_continue
}
}
}
}
catch { interact }
The above probably won't work just like that and it might have some errors as well. It should give you clues as what to do.
But if you're using telnet and are not worried about passwords, why not use rsh instead ? Or even ssh + RSA/DSA authentication ?
G.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-14-2003 05:19 AM
тАО04-14-2003 05:19 AM
Re: using telnet command in shell script
autoexpect -f
#where
After the script is created you will need to edit it and remove a few lines out (such as date/time) if you don't the script won't work. I'm attaching a sample scpect script of mine used to launch stm.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-14-2003 06:31 AM
тАО04-14-2003 06:31 AM
Re: using telnet command in shell script
Thanks
Zafar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-14-2003 08:37 AM
тАО04-14-2003 08:37 AM
Re: using telnet command in shell script
I recommend that you use secure shell instead. It is supported in almost every version of Linux. There is nothing you can do in telnet that you also can't do with the secure utilities.
I have attached a document on installing and using secure shell.
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-14-2003 09:29 AM
тАО04-14-2003 09:29 AM
Re: using telnet command in shell script
I dont recommend opening a telnet session from a script.
Regards,
Shannon
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-14-2003 11:52 AM
тАО04-14-2003 11:52 AM
Re: using telnet command in shell script
Even with the limited ftp command set, this is not recommended.
If you try to automate 'telnet' you can try using the .netrc file but telnet has no limited ftp command set. In short, you're asking for trouble.
Here is one example of the .netrc login. You'd create a unique account designed for automatic logins only and add .netrc here. Here is an example; I've only tested it with ftp:
machine hpxdzg login guest password secret
http://docs.hp.com/cgi-bin/fsearch/framedisplay?top=/hpux/onlinedocs/B2355-90696/B2355-90696_top.html&con=/hpux/onlinedocs/B2355-90696/00/00/73-con.html&toc=/hpux/onlinedocs/B2355-90696/00/00/73-toc.html&searchterms=.netrc&queryid=20030414-134437
By the way, your password will be viewable to anyone over the network with tcpdump or ethereal, et al., since it's not encrypted and sent over the LAN in plain text. This is the main reason people use SSH.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-15-2003 12:40 AM
тАО04-15-2003 12:40 AM
Re: using telnet command in shell script
If you want simply use a script you can do that. But it's totally unsecure.
In a file (name ToDo) put all commands you want to pass in the telnet session.
...
In an other file "ScriptFile"
telnet @IP < ToDo
And execute ScriptFile
It works in a lot of case.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-15-2003 01:35 AM
тАО04-15-2003 01:35 AM
Re: using telnet command in shell script
Thank You so much for your valuable suggestions.
when i use expect i am getting error saying bad interpretor.what does it means.
i am running it in Linux apache web server
can you help me in that.
Thanks in Advance.
Rama
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-15-2003 01:35 AM
тАО04-15-2003 01:35 AM
Re: using telnet command in shell script
Thank You so much for your valuable suggestions.
when i use expect i am getting error saying bad interpretor.what does it means.
i am running it in Linux apache web server
can you help me in that.
Thanks in Advance.
Rama
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-15-2003 02:14 AM
тАО04-15-2003 02:14 AM
Re: using telnet command in shell script
2. what? runing expect in a linux apache web server.
is expect installed. if yes, does the first line of ur script looks something like this.
#!/path/to/expect.
if not download the binary package for expect and install it.
hth
-balaji