SUMMARY: vxquota

From: Geoff Lamb (G.Lamb@epa.ericsson.se)
Date: Tue Jan 20 1998 - 22:25:40 CST


Hi,

Sorry it took so long for the summary.

My question was:
----------------
We run vxquota on our file server and we want users to be able
to check their own quota from nfs mounted SunOS and Solaris boxes.

The suggestions
----------------

I only got one reply - from "Birger A. Wathne" <birger@Vest.Sdata.No>
with
>One of my customers had a similar problem with a DEC server.
>They set up the file server to allow NIS users to log in, but overrides
>their shell so when a user does an 'rsh fileserver' (s)he gets a nicely
>formatted screen showing quota usage on all file systems.
>
>Birger

Sun said that other people had requested this feature and it will not be
implemented soon. They also suggested that I can run vxquota on the file
server and rcp the
file to an accessable place by the users and set up a script to grep out
the relevent
parts.

My Solution
-------------

I ended up writing a couple of perl scripts. One that runs on the server
and listens
for connection to port that set up and sends back the output from
vxquota down the
connected socket. The client (vxquota.pl) can be run on any machine with
perl and
will send back the users quota if you give no file arguments and any
users quota
if you give it a username.

Let me know if you see any bugs

Geoff

The scripts
-------------

----begin server part----

#!/opt/local/bin/perl -Tw
#
# vxquotasrv.pl
#
# vxquota server - listens on $port for connections and send back the
# result of vxquota.
#
# Geoff Lamb
# eeagsl@epa.ericsson.se
# 980121
#
 
require 5.003;
use strict;
BEGIN { $ENV{PATH} = '/usr/ucb:/bin' }
use Socket;
use Carp;
 
sub spawn; # forward declaration
sub logmsg { print "$0 $$: @_ at ", scalar localtime, "\n" }
 
my $port = shift || 8968;
my $proto = getprotobyname('tcp');
socket(Server, PF_INET, SOCK_STREAM, $proto) or die "socket: $!";
setsockopt(Server, SOL_SOCKET, SO_REUSEADDR, pack("l", 1))
                                             or die "setsockopt: $!";
bind(Server, sockaddr_in($port, INADDR_ANY)) or die "bind: $!";
listen(Server,SOMAXCONN) or die "listen: $!";
 
logmsg "server started on port $port";
 
my $waitedpid = 0;
my $paddr;
 
sub REAPER {
    $SIG{CHLD} = \&REAPER; # if you don't have sigaction(2)
    $waitedpid = wait;
}
 
$SIG{CHLD} = \&REAPER;
 
for ( ; $paddr = accept(Client,Server); close Client) {
    my($port,$iaddr) = sockaddr_in($paddr);
    my $name = gethostbyaddr($iaddr,AF_INET);
 
    logmsg "connection from $name [",
            inet_ntoa($iaddr), "]
            at port $port";
 
    spawn sub {
        my $msg = "";
 
# Gets the username from the client
        recv (Client, $msg, 20, 0) or die "recv: $!";
        my @args = ("/usr/sbin/vxquota", "-v", "$msg");
        exec(@args) == 0 or die "system: $!";
    };
 
}
 
sub spawn {
    my $coderef = shift;
 
    unless (@_ == 0 && $coderef && ref($coderef) eq 'CODE') {
        confess "usage: spawn CODEREF";
    }
 
    my $pid;
    if (!defined($pid = fork)) {
        logmsg "cannot fork: $!";
        return;
    } elsif ($pid) {
        logmsg "begat $pid";
        return; # i'm the parent
    }
    # else i'm the child -- go spawn
 
    open(STDIN, "<&Client") or die "can't dup client to stdin";
    open(STDOUT, ">&Client") or die "can't dup client to stdout";
    ## open(STDERR, ">&STDOUT") or die "can't dup stdout to stderr";
    exit &$coderef();
}

----end server part----

----begin client part----
#!/opt/local/bin/perl -w
#
# vxquota.pl
#
# connects to machine $remote on $port which is (hopefully) running
# a server that listens on $port and sends back the vxquota for $usern
#
# Geoff Lamb 21/1/98
#
 
require 5.002;
use strict;
use Socket;
use File::Basename qw(basename);
  
my $Progname = basename($0);
 
die "usage: $Progname [username remote port]\n" unless scalar(@ARGV) <
3;
 
#print $ARGV[0];
 
my ($usern,$remote,$port, $iaddr, $paddr, $proto, $line);
 
$usern = shift || "$<";
$remote = shift || 'brsf00';
$port = shift || 8968; # half random port - my birthday :-)
 
if ($port =~ /\D/) {
  $port = getservbyname($port, 'udp');
  print "what are we doing here? \n";
}
 
die "No port" unless $port;
$iaddr = inet_aton($remote) || die "no host: $remote";
$paddr = sockaddr_in($port, $iaddr);
$proto = getprotobyname('tcp');
socket(SOCK, PF_INET, SOCK_STREAM, $proto) || die "socket: $!";
 
connect(SOCK, $paddr) || die "connect: $!";
 
my $msg = '';
 
send(SOCK, "$usern", 0) || die "send: $!";
 
while ($line = <SOCK>) {
    print $line;
}
 
close (SOCK) || die "close: $!";
 
exit;

----end client part----

---------
   __&__
  / \ Geoff Lamb, Ericsson Data Australia
 | |
 | (o)(o) Internet: eeagsl@epa.ericsson.se
 C .---_) Phone: +61 3 9301 3597
  | |.___| Fax: +61 3 9301 3566
  | \__/
  /_____\
 /_____/ \
/ \
Segmentation fault (core dumped)



This archive was generated by hypermail 2.1.2 : Fri Sep 28 2001 - 23:12:29 CDT