From: Dave D. <rad...@ho...> - 2009-01-02 20:53:14
|
Hey guys, I'm having some problems figuring out how to accomplish the below. I'll forwarn i'm slightly newer to expect, i understand how to use it to do what i want on a machine, but i've never done things on the local machine mid stream and not even sure if it's doable while having a working spawn'd connection up and running. I'm trying to create directories on a remote machine by using ssh. What i want to do is something like below. sub CreateAdditionalDirectories { foreach $line(@servers) { $command = "ssh $username\@$line"; my $exp1 = Expect->spawn($command) or die "Cannot spawn $command: #!\n"; @match_patterns = ("Password"); $patidx = $exp1->expect($timeout, @match_patterns); $exp1->send("$password\r"); foreach $createdirectories(@createdirectories) { @match_patterns = ("bash"); $patidx = $exp1->expect($timeout, @match_patterns); $exp1->send("/usr/local/bin/sudo mkdir $HOMEDIR/$createme/incoming/$directory\r"); @match_patterns = ("bash"); $patidx = $exp1->expect($timeout, @match_patterns); $exp1->send("/usr/local/bin/sudo mkdir $HOMEDIR/$createme/pub/$directory\r"); @match_patterns = ("bash"); $patidx = $exp1->expect($timeout, @match_patterns); }; }; }; Is the above doable? basically i want to prevent establishing multipul ssh connections to the machine if i don't have to. Is their a way to spawn ssh connection, then come back to just normal perl and evaluate a variable, then act based on that variable? Thanks in advance, Dave _________________________________________________________________ Send e-mail anywhere. No map, no compass. http://windowslive.com/oneline/hotmail?ocid=TXT_TAGLM_WL_hotmail_acq_anywhere_122008 |