Displaying keyword search results 1 - 3
Created by Dr. Xi on February 09, 2011 15:35:41 Last update: February 09, 2011 15:36:08
Perl BEGIN and END blocks are executed at the beginning and at the end of a running Perl program. By the Perl doc : A BEGIN code block is executed a s soon as possible , that is, the moment it is completely defined, even before the rest of the containing file (or string) is parsed . You may have multiple BEGIN blocks within a file (or eval'ed string); they will execute in order of definition. Because a BEGIN code block executes immediately, it can pull in definitions of subroutines and such from other files in time to be visible to the rest of the compile and run time. Once a BEGIN has run, it is immediately undefined and any code it used is returned...
Created by Dr. Xi on December 05, 2009 20:12:16 Last update: December 05, 2009 20:46:45
It's quite easy for Perl to open a pipe and read from it:
$file = "nospace.txt"; open(IN, "cat $file |") ...But the code breaks when the file name contains a space:
# This does not work! $file = "yes space.txt"; ...On Windows, these don't work either:
# This does not work! $file = "yes space.txt"; ...You need to use a technique called Safe Pipe Opens :
$file = "yes space.txt"; $prog = "cat"; ...
Created by Dr. Xi on October 06, 2008 22:48:08 Last update: October 06, 2008 22:50:11
A first attempt would be to create an input file like this:
userid password shell_command1 shell_...and feed the lines to the telnet client:
cat telnet_input.txt | telnet remote_host #...However, you'll learn soon enough that it doesn't work. You get output like this:
Trying 192.168.159.128... Connected to bash...What's happening? The telnet client depleted all input before the remote host had a chance to respond. Since there's no more input, the telnet client initiated to close the connection. Adding a delay between the commands makes it work:
(echo userid sleep 10 echo password ...How much time to sleep between commands is just guesswork. You can use Expect to provide more control over the automated session:
#!/usr/bin/expect # timeout script aft......