I am able to make a directory by using telnet session and by using
list (for server name and IPs).
But I am unable to use file for getting name and IPs of server. And
also transfer a file via FTP to created Directory.
Can you please help me
I can't help you with all of that.
I have no idea how to do that, but from what I know, Expect is the
tool you should look for, which seems to work with Tcl as well:
http://wiki.tcl.tk/201
I guess you can write a script and Expect knows Tcl commands and
extends Tcl with some more commands to do the server/login-stuff.
###############################
namespace eval ::srvupdate {}
proc ::srvupdate::ReadSrvs {} {
set srv_file "../servers.dat"
set ret_list [list]
if [catch {open $srv_file r} fileIdread] {
return -code error "$::errorInfo: $srv_file"
} else {
set fileVar [read $fileIdread]
close $fileIdread
set fileList [split $fileVar "\n"]
foreach line $fileList {
if {[scan $line "%s %s" srv_name ip] == 2} {
lappend ret_list $srv_name $ip
}
}
}
return $ret_list
}
proc ::srvupdate::DoExpectThing {} {
foreach {srv_name ip} [ReadSrvs] {
#
# Use Expect here
#
ExpectWrap $srv_name $ip
}
}
proc ::srvupdate::ExpectWrap {srv_name ip} {
# connect
# do the login stuff and whatever
puts "$srv_name $ip"
}
::srvupdate::DoExpectThing
###################################
This only is a starting point.
This script reads your servers from servers.dat (change path) and now
the question is, what to do in "ExpectWrap".
Maybe someone else can help you with that.
Check out http://wiki.tcl.tk/201 with lots of information.
Regards,
Eiji
################################
set username <username>
set passed <password>
foreach server {srv1 srv2 srv3 srv4 srv5} ipadd {<ip1> <ip2> <ip3>
<ip4> <ip5>} {
spawn telnet $ipadd;
expect "username:";
send "$username\r";
expect "password:";
send "$password";
expect "ftp>";
send "mkdir /home/<dirname>\r";
expect "ftp>";
send "exit\r";
}
this is working well. I am able to create a directory as well.
But Instead of those 2 list, I want to use a file which is having
server entries as below.
srv1 xxx.xxx.xx.xxx
srv2 xxx.xxx.xx.xxx
srv3 xxx.xxx.xx.xxx
srv4 xxx.xxx.xx.xxx
srv5 xxx.xxx.xx.xxx
script should read the file, take name and IP, create a folder, FTP
the test file from local machine to respective server.
What problem I am facing is
1) I am not able to read the file and get server name and IP
2) while I am in Telnet session, how do I enter in FTP session to
transfer a file
> What problem I am facing is
> 1) I am not able to read the file and get server name and IP
> 2) while I am in Telnet session, how do I enter in FTP session to
> transfer a file
For 1)
This should work with the code above:
####################
proc ::srvupdate::ExpectWrap {srv_name ipadd} {
# connect
# do the login stuff and whatever
set password "my_password"
set username "my_username"
spawn telnet $ipadd;
expect "username:";
send "$username\r";
expect "password:";
send "$password";
expect "ftp>";
send "mkdir /home/<dirname>\r";
expect "ftp>";
send "exit\r";
#puts "$srv_name $ip"
}
##########################
I just changed ExpectWrap to do the Expect-magic.
You still have to change "set srv_file "../servers.dat"" to points to
the right file.
When it come to the file transfer I'm lost.
That's not my sector. Sorry.
Regards,
Eiji
From your 1st reply my problem was solved. The code worked perfactly.
Only thing where I was getting confused is while running in telnet
session is it possible to invoke ftp session or not.
But Thanks very much for the precious time and help.
I've lost track of your goal.
Yes, it certainly is possible to launch an FTP session from a telnet section.
Do any other questions remain for you?
Here's how:
if {[catch {open $filename r} fh] != 0} {
# cannot open $filename, error message is in $fh
error $fh
}
while {[gets $fh line] != -1} {
foreach {server ipadd} [split $line] break
puts "handling server $server ($ipadd)"
# do your ftp thing
}
close $fh
--
Glenn Jackman
Write a wise saying and your name will live forever. -- Anonymous
My entire problem is solved.
Thanks for the help and time.