Question

The nmap tool has such a feature - when you're performing a scan [#nmap -A -T4 localhost] and press "Enter" - it displays kind of status information "Timing: About 6.17% done"

Question - how can I force this keypress to happen repeatedly without touching a keyboard in bourne shell?

ps: just trying to find a work-around for a bug in php's proc_open function, when stdout of a process is returned only after closing stdout pipe, and php's pty emulation doesn't work on fbsd.

Question closed. Problem solved with the "expect" utility

#!/usr/local/bin/expect

spawn /usr/local/bin/nmap -A -T4 -p 21-100 localhost
expect arting {sleep 3; send \r}
while {1} {
        expect eof {
            send_user "finished\n";
            exit;
        } "done;" {
            sleep 3;
            send \r;
            continue;
        }

}
Was it helpful?

Solution

Probably easiest to use expect.

OTHER TIPS

Maybe the ultimate 'yes man' program will do what you need - the program is called 'yes' and repeatedly generates the same input line over and over.

yes ok | recalcitrant.php 

This will send 'ok' plus newline to the recalcitrant PHP frequently. It is rate-limited by the speed at which the receiving program reads its inputs. It is available in the GNU utilities, and on most other Unix-based platforms.

If you need any intelligence in the processing, though, then the Tcl-based 'expect'

Note, you can get rid of the infinite loop:

spawn /usr/local/bin/nmap -A -T4 -p 21-100 localhost
expect arting {sleep 3; send \r}
expect {
    "done;" {
        sleep 3
        send \r
        exp_continue
    }
    eof
}
puts "finished"

Are you sure you need the sleeps? They can usually be avoided by using -regexp matching with the expect command.

Helpful Expect tip: while developing, use exp_internal 1 to verbosely see how your patterns are matching the command output.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top