/* @(#)rstat.c 2.3 88/11/30 4.0 RPCSRC */
* Simple program that prints the status of a remote host, in a format
* similar to that used by the 'w' command, using the rstat.x service.
#include <rpc/rpc.h> /* include <sys/time.h> */
fprintf(stderr
, "usage: %s \"host\"\n", argv
[0]);
/* client handle to rstat */
rstat_clnt
= clnt_create(host
, RSTATPROG
, RSTATVERS_TIME
, "udp");
clnt_pcreateerror(argv
[0]);
host_stat
= rstatproc_stats_3(NULL
, rstat_clnt
);
clnt_perror(rstat_clnt
, argv
[0]);
tmp_time
= localtime(&host_stat
->curtime
.tv_sec
);
host_stat
->curtime
.tv_sec
-= host_stat
->boottime
.tv_sec
;
tmp_time
= gmtime(&host_stat
->curtime
.tv_sec
);
if (host_uptime
.tm_yday
!= 0)
sprintf(days_buf
, "%d day%s, ", host_uptime
.tm_yday
,
(host_uptime
.tm_yday
> 1) ? "s" : "");
if (host_uptime
.tm_hour
!= 0)
sprintf(hours_buf
, "%2d:%02d,",
host_uptime
.tm_hour
, host_uptime
.tm_min
);
if (host_uptime
.tm_min
!= 0)
sprintf(hours_buf
, "%2d mins,", host_uptime
.tm_min
);
printf(" %2d:%02d%cm up %s%s load average: %.2f %.2f %.2f\n",
(host_time
.tm_hour
> 12) ? host_time
.tm_hour
- 12
(host_time
.tm_hour
>= 12) ? 'p'
(double)host_stat
->avenrun
[0]/FSCALE
,
(double)host_stat
->avenrun
[1]/FSCALE
,
(double)host_stat
->avenrun
[2]/FSCALE
);