- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: Telnet 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
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
тАО07-14-2003 07:34 PM
тАО07-14-2003 07:34 PM
Can anyone show me a sample script that can automatically telnet into another server and execute another script within that server.
I need to create one and pattern it from your sample.
Thanks as I don't have any scripting skills whatsoever.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-14-2003 07:57 PM
тАО07-14-2003 07:57 PM
SolutionIf it does need to be 'telnet', then it's easiest (or perhaps more stable) to use expect.
Most modern linux distributions would come with Expect.
A simple expect script could be something like:
---------------------------------------#!/usr/bin/expect
set timeout -1
spawn /usr/bin/telnet
expect "login:"
send "
expect "password:"
send "
expect "]$"
send "yourcommand\r"
expect "]$"
---------------------------------------
The man page for Expect can tell you more.
You can truely do some amazing stuff with expect.. A bit of TCl knowledge and you're laughing ;)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-14-2003 07:58 PM
тАО07-14-2003 07:58 PM
Re: Telnet Script
+++++++++++++++cut here+++++++++++++++++++++++
#!/usr/bin/expect -f
#
# This script telnets to a specific host as a specifc user and sets the required
# environment variables.
#Change default timeout
set timeout 100
#Variables. Change as necessary
set TERM xterm ;#default TERM
set prompt "(%|#|\\$) $" ;# default prompt
catch {set prompt $env(EXPECT_PROMPT)}
#Host Name
set SERVER "[lrange $argv 0 0]"
set USER "[lrange $argv 1 1]"
set PASSWD "[lrange $argv 2 2]"
#Command List
set COMMANDS "[lrange $argv 3 $argc]"
#Spawn Telnet
spawn telnet
expect "telnet> "
#Initialise a Connection
send "open $SERVER\r"
#Login to the Server
expect {
-re "Connection timed out" {
send_user "Unable to connect to $host. Exiting..."
exit 1
}
timeout {
send_user "Timed out connecting to $host. Exiting..."
exit 1
}
"login* "
}
send "$USER\r"
expect "Password:*"
send "$PASSWD\r"
expect {
-re "Login incorrect*" {
send_user "Looks like the password is wrong. Spawning a shell..."
interact
exit 1
}
-re $prompt
}
#loop through arguments
foreach command $COMMANDS {
send "$command\r"
expect -re $prompt
}
send_user "Expect Scripts Ends. Good Bye!!!\n"
+++++++++++++++cut here+++++++++++++++++++++++
call this script as
scriptname servername username password command[s]
and, if you want to have a basic script and then work out from there, check out autoexpect.
snipped below is from the man page of autoexpect.
++++++++++++++++++++++++++++++++++++++++++++++
AUTOEXPECT(1) AUTOEXPECT(1)
NAME
autoexpect - generate an Expect script from watching a session
SYNOPSIS
autoexpect [ args ] [ program args... ]
INTRODUCTION
autoexpect watches you interacting with another program and creates an Expect script that reproduces your interactions. For
straightline scripts, autoexpect saves substantial time over writing scripts by hand. Even if you are an Expect expert, you will
find it convenient to use autoexpect to automate the more mindless parts of interactions. It is much easier to cut/paste hunks of
autoexpect scripts together than to write them from scratch. And if you are a beginner, you may be able to get away with learning
nothing more about Expect than how to call autoexpect.
++++++++++++++++++++++++++++++++++++++++++++++
hth
-balaji
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-14-2003 08:00 PM
тАО07-14-2003 08:00 PM
Re: Telnet Script
and mine was missing (at the very least) a ' --' on the fisrt line..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-14-2003 08:05 PM
тАО07-14-2003 08:05 PM
Re: Telnet Script
-balaji
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-14-2003 08:08 PM
тАО07-14-2003 08:08 PM
Re: Telnet Script
to add to that Stuart, one thing i have mastered from Windows is the art of Ctrl+C and Ctrl+V
-balaji
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-14-2003 08:21 PM
тАО07-14-2003 08:21 PM
Re: Telnet Script
The expect routine we use for stuff like that is a little more complex.. about 5kb back-ended with a PHP script (7kb) and an Interbase database (1.2mb) with all the hosts and authentication details of our various client sites.. Much fun ;)
The above was vaguely copied from the quick-hack routine :P
0pts here too pls.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-15-2003 03:11 AM
тАО07-15-2003 03:11 AM
Re: Telnet Script
I'm attaching a script
all you need to do is change your username and your password and the servername
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-15-2003 11:29 AM
тАО07-15-2003 11:29 AM
Re: Telnet Script
After install of expect
use this script
Caesar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-19-2003 07:31 AM
тАО09-19-2003 07:31 AM
Re: Telnet Script
expect {
timeout { exit 1 }
"login*"
}
keep getting error
invalid command name "
timeout {
exit 1
}
"login: "
"
Another question is about match_max, set timeout; when there are a large amount of data coming from the remote server which size is larger than match_max and the time is longer than the timeout, the script exit at timeout interval which is unexpected.
Could anybody help on this?
Many Thanks!