If anyone is interested this is kind of neat and demo-
nstrates how flexible gawk 3.0.95+ can be.
Any suggestions on how to improve it are welcomed.
function interpreter(cmd,auth, list) {
if (auth && cmd) {
print "Sending", cmd
while ((cmd | getline) > 0) {
list = length(list) < 1 ? $0"\n" : list"\n"$0
}
}
close(cmd)
return list
}
BEGIN {
passwd = "bogus"
socket = "/inet/tcp/2300/0/0"
while (1) {
while ((socket |& getline) > 0) {
if (!auth) {
printf "Password: " |& socket
if ((socket |& getline) > 0 && $0 == passwd) {
auth = 1
} else {
print "Sorry, wrong password: ",$0 |& socket
auth = 0
}
}
print "AwkRemote Command Shell--> #", cnt |& socket
res = interpreter($0,auth)
print res |& socket
}
close(socket)
auth = 0
socket |& getline
}
}
nstrates how flexible gawk 3.0.95+ can be.
Any suggestions on how to improve it are welcomed.
function interpreter(cmd,auth, list) {
if (auth && cmd) {
print "Sending", cmd
while ((cmd | getline) > 0) {
list = length(list) < 1 ? $0"\n" : list"\n"$0
}
}
close(cmd)
return list
}
BEGIN {
passwd = "bogus"
socket = "/inet/tcp/2300/0/0"
while (1) {
while ((socket |& getline) > 0) {
if (!auth) {
printf "Password: " |& socket
if ((socket |& getline) > 0 && $0 == passwd) {
auth = 1
} else {
print "Sorry, wrong password: ",$0 |& socket
auth = 0
}
}
print "AwkRemote Command Shell--> #", cnt |& socket
res = interpreter($0,auth)
print res |& socket
}
close(socket)
auth = 0
socket |& getline
}
}