Unix::Sysadmin::Host - Networked host information class
use Unix::Sysadmin::Host;
$host = Unix::Sysadmin::Host->new();
returns an empty Host:: object
This class describes networked hosts. Currently four OS varieties are supported. They are FreeBSD, OpenBSD, SunOS (Solaris) and Linux.
new()
load(FILEHANDLE)
thisHost()
name()
The object's hostname.
aliases()
ip()
os()
The object's OS architecture. This is a hash with the following structure:
{ NAME => OS name, # 'FreeBSD', 'OpenBSD', 'SunOS' or 'Linux' MAJOR => Major rev, MINOR => Minor rev, TEENY => Really minor rev, }
arch()
upreserve()
usermap()
Set the value by passing either a hashref as described above, or a colon separated list of key=value pairs in a string.
gpreserve()
groupmap()
Set the value by passing either a hashref as described above, or a colon separated list of key=value pairs in a string.
amtype()
rp()
sshkey()
=item validsortorders()
get the fields that User records may be sorted by. These are:
byHostname byOs
defaultsortorder()
This returns 'byHostname'
$self->cmd("RCP");
returns ``/usr/bin/rcp'' for a Linux host and ``/bin/rcp'' for a Solaris host.
The second form sets a local override for a command. Example:
$self->cmd("RCP","/opt/my/bin/rcp");
Sets this objects idea of what RCP is to ``/opt/my/bin/rcp''. This is the value that will be returned henceforth for this object instance. To set a permanent override, add a ``command='' clause to the host's entry in the host list (See the Unix::Sysadmin::Host.list manpage.)
$self->file("PW") ;
returns ``/etc/passwd'' for a Linux host and ``/etc/master.passwd'' for a BSD host.
The second form sets a local override for a file. Example:
$self->cmd("PW","/var/yp/passwd");
Sets this objects idea of where the passwd file is to ``/var/yp/passwd''. This is the value that will be returned henceforth for this object instance. To set a permanent override, add a ``file='' clause to the host's entry in the host list (See the Unix::Sysadmin::Host.list manpage.)
dump()
getFiles()
$self->getFiles( { FROMHOST => $host, TOFILES => $tofilename|[tofile0, tofile1, ...], FROMFILES => $fromfilename|[fromfile0, fromfile1, ...], USERSH => 0|undef|1, } );
Get files from the host stored in $host to $self->thisHost()
The
host in $host may be this host, or a remote host. Single files are
represented with scalar strings. Multiple files are passed as
references to arrays containing the filename strings. If multiple
files are specified, the number of entries in the fromfile array
must match the number in the tofile array. $fromfile[0] will be
copied to $tofile[0] and so forth. If $host is a remote host, scp
is used by default. If the USERSH parameter has a non-zero value,
rcp will be used instead.
putFiles()
putFiles ( { TOHOST => $host, TOFILES => $tofilename|[tofile0, tofile1, ...], FROMFILES => $fromfilename|[fromfile0, fromfile1, ...], USERSH => 0|undef|1, } );
Copy files $self->thisHost()
to the host stored in $host. The host
in $host may be this host, or a remote host. Single files are
represented with scalar strings. Multiple files are passed as
references to arrays containing the filename strings. If multiple
files are specified, the number of entries in the fromfile array
must match the number in the tofile array. $fromfile[0] will be
copied to $tofile[0] and so forth. If $host is a remote host, scp
is used by default. If the USERSH parameter has a non-zero value,
rcp will be used instead.
installFiles()
installFiles ( { TOHOST => $host, TOFILES => $tofilename|[tofile0, tofile1, ...], FROMFILES => $fromfilename|[fromfile0, fromfile1, ...], USERSH => 0|undef|1, USEVERSIONS => 0|undef|1, OTHERDIR => 0|undef|1, } );
Backup the files named in TOFILES using $self->backupFiles()
Otherwise identical to putFiles()
above.
backupFiles()
backupFiles( { TOHOST => $host, TOFILES => $tofilename|[tofile0, tofile1, ...], USERSH => 0|undef|1, USEVERSIONS => 0|undef|1, OTHERDIR => 0|undef|1, } );
Backup file(s)
on TOHOST to files named with a ``.bak'' extension. If OTHERDIR is given,
place the backups in that directory rather than the one the file lives in. If USEVERSIONS
is given, backup to file(s)
named <filename>.<n>
where <n>
is a
non-zero, positive integer. E.g if four backups of the file ``foo.txt'' existed, this method
would create a fifth backup file called ``foo.txt.5'', by copying ``foo.txt.4''. All other
backups would be renamed to their next higher version number. Finally ``foo.txt'' would be copied
to ``foo.txt.1''. Holes in the sequence will be filled in by this process. But ``file.n+1'' is guaranteed
to be older than ``file.n''. The number of backups is not constrained by this method. Use
purgeBackups()
to manage the number of backups retained.
purgeBackups()
purgeBackups( { TOHOST => $host, TOFILES => $tofilename|[tofile0, tofile1, ...], KEEP => n, OTHERDIR => 0|undef|1, USERSH => 0|1|undef, } );
Delete backups created by the backupFiles()
method. Keep the KEEP newest versions,
or none if KEEP is not given. Process backups in OTHERDIR rather than the director(y|ies)
TOFILES live in if given.
doCmd()
doCmd ( { HOST => $host, COMMAND => "COMMAND", ARGS => [ "arg0", "arg1", . . "argn", ], USERSH => 0|1|undef, } ) Execute the given command on the host stored in $host. The command is an uppercase string taken from the Unix::Sysadmin::Cmds::<arch> object appropriate for the host in $host. When $host is a remote host, uses ssh by default, unless overridden by the USERSH parameter ARGS is a reference to an array containing arguments to the command.
Man(3)
pages (programmer's docs):
the Unix::Sysadmin::Host manpage, the Unix::Sysadmin::User manpage, the Unix::Sysadmin::Automount manpage, the Unix::Sysadmin::Group manpage, the Unix::Sysadmin::Netgroup manpage, the Unix::Sysadmin::List manpage, the Unix::Sysadmin::Cmds manpage, the Unix::Sysadmin::Files manpage the Unix::Sysadmin::Utility manpage the Unix::Sysadmin::Config manpage, the Unix::Sysadmin::Scoped manpage
Man(4)
pages (file formats):
the Unix::Sysadmin::Host.list manpage, the Unix::Sysadmin::User.list manpage, the Unix::Sysadmin::Automount.list manpage, the Unix::Sysadmin::Group.list manpage, the Unix::Sysadmin::Netgroup.list manpage
Man(1m)
pages (manager's docs):
the Unix::Sysadmin manpage, the Unix::Sysadmin::Setup manpage the usasetup manpage
Howard Owen <hbo@egbok.com> =cut