cvs: phpdoc /en/reference/expect reference.xml

From: Date: Mon, 01 Oct 2007 21:01:16 +0000
Subject: cvs: phpdoc /en/reference/expect reference.xml
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-120@lists.php.net to get a copy of this message
michael Mon Oct 1 21:01:16 2007 UTC Modified files: /phpdoc/en/reference/expect reference.xml Log: Add another example to the manual http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/expect/reference.xml?r1=1.6&r2=1.7&diff_format=u Index: phpdoc/en/reference/expect/reference.xml diff -u phpdoc/en/reference/expect/reference.xml:1.6 phpdoc/en/reference/expect/reference.xml:1.7 --- phpdoc/en/reference/expect/reference.xml:1.6 Wed Jun 20 22:24:26 2007 +++ phpdoc/en/reference/expect/reference.xml Mon Oct 1 21:01:16 2007 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.6 $ --> +<!-- $Revision: 1.7 $ --> <!-- Purpose: fileprocess.process --> <!-- Membership: pecl --> @@ -60,8 +60,7 @@ array (0 => "password:", 1 => PASSWORD) ); -switch (expect_expectl ($stream, $cases)) -{ +switch (expect_expectl ($stream, $cases)) { case PASSWORD: fwrite ($stream, "password\n"); break; @@ -78,6 +77,80 @@ ]]> </programlisting> </example> + + <para> + The following example connects to the remote host, determines whether + installed OS is for 32 or 64 bit, then runs update for specific package. + </para> + <example> + <title>Another Expect Usage Example</title> + <programlisting role="php"> +<![CDATA[ +<?php +ini_set ("expect.timeout", -1); +ini_set ("expect.loguser", "Off"); + +$stream = expect_popen ("ssh root@remotehost"); + +while (true) { + switch (expect_expectl ($stream, array ( + array ("password:", PASSWORD), // SSH is asking for password + array ("yes/no)?", YESNO), // SSH is asking whether to store the host entry + array ("~$ ", SHELL, EXP_EXACT), // We've got the shell! + ))) { + case PASSWORD: + fwrite ($stream, "secret\n"); + break; + + case YESNO: + fwrite ($stream, "yes\n"); + break; + + case SHELL: + fwrite ($stream, "uname -a\n"); + while (true) { + switch (expect_expectl ($stream, array ( + array ("~$ ", SHELL, EXP_EXACT), // We've got the shell! + array ("^Linux.*$", UNAME, EXP_REGEXP), // uname -a output + ), $match)) { + case UNAME: + $uname .= $match[0]; + break; + + case SHELL: + // Run update: + if (strstr ($uname, "x86_64")) { + fwrite ($stream, "rpm -Uhv http://mirrorsite/somepath/some_64bit.rpm\n"); + } else { + fwrite ($stream, "rpm -Uhv http://mirrorsite/somepath/some_32bit.rpm\n"); + } + fwrite ($stream, "exit\n"); + break 2; + + case EXP_TIMEOUT: + case EXP_EOF: + break 2; + + default: + die ("Error has occurred!\n"); + } + } + break 2; + + case EXP_TIMEOUT: + case EXP_EOF: + break 2; + + default: + die ("Error has occurred!\n"); + } +} + +fclose ($stream); +?> +]]> + </programlisting> + </example> </section> </partintro>

« previous php.doc.cvs (#120) next »