#!/usr/local/bin/sybperl
#
#	@(#)space.pl	1.2	4/2/93

require "sybperl.pl";
require "sql.pl";

#
# Log us in to Sybase.
#
print "Name of Sybase server: ";
$server = <>; chop($server);
if($server ne '')
{
    $ENV{'DSQUERY'} = $server;
}
else
{
    $server = $ENV{'DSQUERY'};
}

print "Administrative account password: ";
eval `stty -echo`;
$sapw = <>; chop($sapw);
eval `stty echo`;

$d = &dblogin("sa", $sapw);


$server = $server . '.';


&sql($d, "use master");
@dbs = &sql($d, "select name from sysdatabases order by name");

foreach $n (@dbs) {
    &sql($d, "use $n");
    $x = join('~', &sql($d, 'sp_spaceused'));
    $x =~ s/ //g;
    $x =~ s/MB|KB//g;
    ($name, $size, $res, $data, $index, $free ) = split("~",$x);
    $unused = $size * 1024 - $res;
    write;
    $ts += $size;
    $tr += $res;
    $td += $data;
    $ti += $index;
    $tf += $free;
}

print '-' x 78, "\n"; 
$name = 'TOTAL';
$size = $ts;
$res = $tr;
$data = $td;
$index = $ti;
$free = $tf;
$unused = $size * 1024 - $res;
write;

format top=
Space usage per database for server @<<<<<<<<<<<<<<<
				    $server
Name             Size    Reserved       Data      Index       Free     Unused
	         (MB)        (KB)       (KB)       (KB)       (KB)       (KB)
-----------------------------------------------------------------------------
. 
format stdout=
@<<<<<<<<<  @>>>>>>>>  @>>>>>>>>>  @>>>>>>>>  @>>>>>>>>  @>>>>>>>>  @>>>>>>>>
$name,      $size,     $res,       $data,     $index,    $free,     $unused
. 


