bash command to repeatedly emulate keypress on a proceess
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 localhostexpect arting {sleep 3; send \r}expect { "done;" { sleep 3 send \r exp_continue } eof}puts "finished"
Are you sure you need the sleep
s? 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.