mirror of
https://github.com/freebsd/freebsd-src
synced 2024-11-05 18:22:52 +00:00
rup from FreeBSD 1.1.5.1
Reviewed by: Geoff Submitted by: John Brezak
This commit is contained in:
parent
935a002483
commit
a82f86e105
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/cvs2svn/branches/FBSD_1/; revision=2343
3 changed files with 330 additions and 0 deletions
9
usr.bin/rup/Makefile
Normal file
9
usr.bin/rup/Makefile
Normal file
|
@ -0,0 +1,9 @@
|
|||
# $Id: Makefile,v 1.2 1993/11/10 03:47:06 smace Exp $
|
||||
|
||||
PROG= rup
|
||||
MAN1= rup.1
|
||||
|
||||
DPADD= ${LIBRPCSVC}
|
||||
LDADD= -lrpcsvc
|
||||
|
||||
.include <bsd.prog.mk>
|
94
usr.bin/rup/rup.1
Normal file
94
usr.bin/rup/rup.1
Normal file
|
@ -0,0 +1,94 @@
|
|||
.\" -*- nroff -*-
|
||||
.\"
|
||||
.\" Copyright (c) 1985, 1991 The Regents of the University of California.
|
||||
.\" All rights reserved.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\" 3. All advertising materials mentioning features or use of this software
|
||||
.\" must display the following acknowledgement:
|
||||
.\" This product includes software developed by the University of
|
||||
.\" California, Berkeley and its contributors.
|
||||
.\" 4. Neither the name of the University nor the names of its contributors
|
||||
.\" may be used to endorse or promote products derived from this software
|
||||
.\" without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" $Id: rup.1,v 1.1 1993/09/16 01:15:35 jtc Exp $
|
||||
.\"
|
||||
.Dd June 7, 1993
|
||||
.Dt RUP 1
|
||||
.Os BSD 4.3
|
||||
.Sh NAME
|
||||
.Nm rup
|
||||
.Nd remote status display
|
||||
.Sh SYNOPSIS
|
||||
.Nm rup
|
||||
.Op Ar host ...
|
||||
.Sh DESCRIPTION
|
||||
.Nm rup
|
||||
displays a summary of the current system status of a particular
|
||||
.Em host
|
||||
or all hosts on the local network.
|
||||
The output shows the current time of day, how long the system has
|
||||
been up,
|
||||
and the load averages.
|
||||
The load average numbers give the number of jobs in the run queue
|
||||
averaged over 1, 5 and 15 minutes.
|
||||
.Pp
|
||||
The
|
||||
.Xr rpc.rstatd 8
|
||||
daemon must be running on the remote host for this command to
|
||||
work.
|
||||
.Nm rup
|
||||
uses an RPC protocol defined in /usr/include/rpcsvc/rstat.x.
|
||||
.Sh EXAMPLE
|
||||
.Bd -unfilled -offset indent -compact
|
||||
example% rup otherhost
|
||||
otherhost 7:36am up 6 days, 16:45, load average: 0.20, 0.23, 0.18
|
||||
example%
|
||||
.Ed
|
||||
.Sh DIAGNOSTICS
|
||||
.Bl -tag -width indent
|
||||
.It rup: RPC: Program not registered
|
||||
The
|
||||
.Xr rpc.rstatd 8
|
||||
daemon has not been started on the remote host.
|
||||
.It rup: RPC: Timed out
|
||||
A communication error occurred. Either the network is
|
||||
excessively congested, or the
|
||||
.Xr rpc.rstatd 8
|
||||
daemon has terminated on the remote host.
|
||||
.It rup: RPC: Port mapper failure - RPC: Timed out
|
||||
The remote host is not running the portmapper (see
|
||||
.Xr portmap 8 ),
|
||||
and cannot accomodate any RPC-based services. The host may be down.
|
||||
.El
|
||||
.Sh SEE ALSO
|
||||
.Xr portmap 8 ,
|
||||
.Xr rpc.rstatd 8
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Nm rwall
|
||||
command
|
||||
appeared in
|
||||
.Em Sun-OS .
|
||||
.Sh BUGS
|
||||
The sorting options are not implemented.
|
227
usr.bin/rup/rup.c
Normal file
227
usr.bin/rup/rup.c
Normal file
|
@ -0,0 +1,227 @@
|
|||
/*-
|
||||
* Copyright (c) 1993, John Brezak
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char rcsid[] = "$Id: rup.c,v 1.3 1994/04/10 10:42:28 csgr Exp $";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netdb.h>
|
||||
#include <rpc/rpc.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#undef FSHIFT /* Use protocol's shift and scale values */
|
||||
#undef FSCALE
|
||||
#include <rpcsvc/rstat.h>
|
||||
|
||||
#define HOST_WIDTH 15
|
||||
|
||||
char *argv0;
|
||||
|
||||
struct host_list {
|
||||
struct host_list *next;
|
||||
struct in_addr addr;
|
||||
} *hosts;
|
||||
|
||||
int search_host(struct in_addr addr)
|
||||
{
|
||||
struct host_list *hp;
|
||||
|
||||
if (!hosts)
|
||||
return(0);
|
||||
|
||||
for (hp = hosts; hp != NULL; hp = hp->next) {
|
||||
if (hp->addr.s_addr == addr.s_addr)
|
||||
return(1);
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
void remember_host(struct in_addr addr)
|
||||
{
|
||||
struct host_list *hp;
|
||||
|
||||
if (!(hp = (struct host_list *)malloc(sizeof(struct host_list)))) {
|
||||
fprintf(stderr, "%s: no memory.\n", argv0);
|
||||
exit(1);
|
||||
}
|
||||
hp->addr.s_addr = addr.s_addr;
|
||||
hp->next = hosts;
|
||||
hosts = hp;
|
||||
}
|
||||
|
||||
rstat_reply(char *replyp, struct sockaddr_in *raddrp)
|
||||
{
|
||||
struct tm *tmp_time;
|
||||
struct tm host_time;
|
||||
struct tm host_uptime;
|
||||
char days_buf[16];
|
||||
char hours_buf[16];
|
||||
struct hostent *hp;
|
||||
char *host;
|
||||
statstime *host_stat = (statstime *)replyp;
|
||||
|
||||
if (search_host(raddrp->sin_addr))
|
||||
return(0);
|
||||
|
||||
hp = gethostbyaddr((char *)&raddrp->sin_addr.s_addr,
|
||||
sizeof(struct in_addr), AF_INET);
|
||||
if (hp)
|
||||
host = hp->h_name;
|
||||
else
|
||||
host = inet_ntoa(raddrp->sin_addr);
|
||||
|
||||
/* truncate hostname to fit nicely into field */
|
||||
if (strlen(host) > HOST_WIDTH)
|
||||
host[HOST_WIDTH] = '\0';
|
||||
|
||||
printf("%-*s\t", HOST_WIDTH, host);
|
||||
|
||||
tmp_time = localtime((time_t *)&host_stat->curtime.tv_sec);
|
||||
host_time = *tmp_time;
|
||||
|
||||
host_stat->curtime.tv_sec -= host_stat->boottime.tv_sec;
|
||||
|
||||
tmp_time = gmtime((time_t *)&host_stat->curtime.tv_sec);
|
||||
host_uptime = *tmp_time;
|
||||
|
||||
if (host_uptime.tm_yday != 0)
|
||||
sprintf(days_buf, "%3d day%s, ", host_uptime.tm_yday,
|
||||
(host_uptime.tm_yday > 1) ? "s" : "");
|
||||
else
|
||||
days_buf[0] = '\0';
|
||||
|
||||
if (host_uptime.tm_hour != 0)
|
||||
sprintf(hours_buf, "%2d:%02d, ",
|
||||
host_uptime.tm_hour, host_uptime.tm_min);
|
||||
else
|
||||
if (host_uptime.tm_min != 0)
|
||||
sprintf(hours_buf, "%2d mins, ", host_uptime.tm_min);
|
||||
else
|
||||
hours_buf[0] = '\0';
|
||||
|
||||
printf(" %2d:%02d%cm up %9.9s%9.9s load average: %.2f %.2f %.2f\n",
|
||||
host_time.tm_hour % 12,
|
||||
host_time.tm_min,
|
||||
(host_time.tm_hour >= 12) ? 'p' : 'a',
|
||||
days_buf,
|
||||
hours_buf,
|
||||
(double)host_stat->avenrun[0]/FSCALE,
|
||||
(double)host_stat->avenrun[1]/FSCALE,
|
||||
(double)host_stat->avenrun[2]/FSCALE);
|
||||
|
||||
remember_host(raddrp->sin_addr);
|
||||
return(0);
|
||||
}
|
||||
|
||||
onehost(char *host)
|
||||
{
|
||||
CLIENT *rstat_clnt;
|
||||
statstime host_stat;
|
||||
struct sockaddr_in addr;
|
||||
struct hostent *hp;
|
||||
|
||||
hp = gethostbyname(host);
|
||||
if (hp == NULL) {
|
||||
fprintf(stderr, "%s: unknown host \"%s\"\n",
|
||||
argv0, host);
|
||||
return(-1);
|
||||
}
|
||||
|
||||
rstat_clnt = clnt_create(host, RSTATPROG, RSTATVERS_TIME, "udp");
|
||||
if (rstat_clnt == NULL) {
|
||||
fprintf(stderr, "%s: %s %s", argv0, host, clnt_spcreateerror(""));
|
||||
return(-1);
|
||||
}
|
||||
|
||||
bzero((char *)&host_stat, sizeof(host_stat));
|
||||
if (clnt_call(rstat_clnt, RSTATPROC_STATS, xdr_void, NULL, xdr_statstime, &host_stat, NULL) != RPC_SUCCESS) {
|
||||
fprintf(stderr, "%s: %s: %s\n", argv0, host, clnt_sperror(rstat_clnt, host));
|
||||
return(-1);
|
||||
}
|
||||
|
||||
addr.sin_addr.s_addr = *(int *)hp->h_addr;
|
||||
rstat_reply((char *)&host_stat, &addr);
|
||||
}
|
||||
|
||||
allhosts()
|
||||
{
|
||||
statstime host_stat;
|
||||
enum clnt_stat clnt_stat;
|
||||
|
||||
clnt_stat = clnt_broadcast(RSTATPROG, RSTATVERS_TIME, RSTATPROC_STATS,
|
||||
xdr_void, NULL,
|
||||
xdr_statstime, &host_stat, rstat_reply);
|
||||
if (clnt_stat != RPC_SUCCESS && clnt_stat != RPC_TIMEDOUT) {
|
||||
fprintf(stderr, "%s: %s\n", argv0, clnt_sperrno(clnt_stat));
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
usage()
|
||||
{
|
||||
fprintf(stderr, "Usage: %s [hosts ...]\n", argv0);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int ch;
|
||||
extern int optind;
|
||||
|
||||
if (!(argv0 = rindex(argv[0], '/')))
|
||||
argv0 = argv[0];
|
||||
else
|
||||
argv0++;
|
||||
|
||||
while ((ch = getopt(argc, argv, "?")) != -1)
|
||||
switch (ch) {
|
||||
default:
|
||||
usage();
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
|
||||
setlinebuf(stdout);
|
||||
if (argc == optind)
|
||||
allhosts();
|
||||
else {
|
||||
for (; optind < argc; optind++)
|
||||
(void) onehost(argv[optind]);
|
||||
}
|
||||
exit(0);
|
||||
}
|
Loading…
Reference in a new issue