Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bash command to repeatedly emulate keypress on a proceess

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;
        }

}
like image 936
johnrembo Avatar asked Nov 01 '25 16:11

johnrembo


1 Answers

Probably easiest to use expect.

like image 52
Douglas Leeder Avatar answered Nov 04 '25 09:11

Douglas Leeder



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!