User:GreenC/awb/cygwin/demon-win


 * 1) !/bin/awk -f

@load "filefuncs"

BEGIN {


 * 1) Begin configurations

rm = "/usr/bin/rm"               # Path to Cygwin rm   sleep = "/usr/bin/sleep"          # Path to Cygwin sleep

dir = "/cygdrive/h/"             # Shared directory with VirtualBox. RAM disk recommended. fname = dir "name.txt"           # File containing name passed *from* AWB farticle = dir "article.txt"     # File containing article passed *to* AWB fabort = dir "abort.txt"         # File flagging an abort from remote script


 * 1) End configuration

name = ARGV[1]

# Clear any old files removefile(farticle) removefile(fname) removefile(fabort)

if(length(name) == 0)            # Abort if bad name data exit

print name > fname close(fname)                     # Flush buffer

print("demon-win.awk: Waiting for " farticle " ...")

while(1) { sleep(1) if( exists(fabort) ) { print("demon-win.awk: Received abort.txt") removefile(fabort) exit }   if( exists(farticle) ) { print("demon-win.awk: Received article.txt") exit } } }

function removefile(str) {
 * 1) Delete a file

if( exists(str) ) sys2var(rm " -- " str) if( exists(str) ) { print("demon-lin.awk: Unable to delete " str ", aborting.") exit }     system("") # Flush insurance }

function exists(name   ,fd) { if ( stat(name, fd) == -1) return 0 else return 1 }
 * 1) Check for file existence. Return 1 if exists, 0 otherwise.
 * 2)  Requires GNU Awk:
 * 3)     @load "filefuncs"
 * 1)     @load "filefuncs"

function sys2var(command       ,fish, scale, ship) {
 * 1) Run a system command and store result in a variable
 * 2)   eg. googlepage = sys2var("wget -q -O- http://google.com")
 * 3) Supports pipes inside command string. Stderr is sent to null.
 * 4) If command fails (errno) return null
 * 1) If command fails (errno) return null

command = command " 2>/dev/null" while ( (command | getline fish) > 0 ) { if ( ++scale == 1 ) ship = fish else ship = ship "\n" fish }        close(command) return ship }

function sleep(seconds) { sys2var(sleep " " seconds) }
 * 1) Sleep
 * 1) Sleep