1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
#!/opt/local/bin/gawk -f
# Usage: res_host.awk <time>
#
# Copyright 2001 Stephan Schulz, schulz@informatik.tu-muenchen.de
#
# Reserve a dedicated host for the given user and for a certain time
# by managing a lock file that is checked by long-running
# applications. This is just the front end, the real work is done in
# handle_res.awk.
function get_username( pipe, tmp)
{
pipe = "whoami";
pipe | getline tmp;
close(pipe);
if(!tmp)
{
print "res_host.awk: Cannot get user name?!?" > "/dev/stderr";
exit 1;
}
return tmp;
}
BEGIN{
reserved_hosts["sunjessen56"] = "schulz";
reserved_hosts["sunjessen48"] = "letz";
reserved_hosts["sunjessen51"] = "stenzg";
reserved_hosts["sunjessen57"] = "jobmann";
if(ARGC!=2)
{
duration = 2;
}
else
{
duration = ARGV[1];
}
user = get_username();
ARGV[1] = "";
host = "";
for(i in reserved_hosts)
{
if(reserved_hosts[i]==user)
{
host = i;
break;
}
}
if(host=="")
{
print "res_host: User " user " does not have dedicated host." > "/dev/stderr";
exit 1;
}
print "Will reserve host " host " for user " user " for " duration " hour(s)";
system("handle_res.awk " user " " host " " duration "&");
}
|