Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Awk Inet Rservice ;)

Status
Not open for further replies.

marsd

IS-IT--Management
Apr 25, 2001
2,218
US
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&quot;\n&quot; : list&quot;\n&quot;$0
}
}
close(cmd)
return list
}


BEGIN {
passwd = &quot;bogus&quot;
socket = &quot;/inet/tcp/2300/0/0&quot;

while (1) {
while ((socket |& getline) > 0) {
if (!auth) {
printf &quot;Password: &quot; |& socket
if ((socket |& getline) > 0 && $0 == passwd) {
auth = 1
} else {
print &quot;Sorry, wrong password: &quot;,$0 |& socket
auth = 0
}
}
print &quot;AwkRemote Command Shell--> #&quot;, cnt |& socket
res = interpreter($0,auth)
print res |& socket
}
close(socket)
auth = 0
socket |& getline
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top