NAME

Unix::Sysadmin::Host - Networked host information class


SYNOPSIS

 use Unix::Sysadmin::Host;
 $host = Unix::Sysadmin::Host->new();
 returns an empty Host:: object


DESCRIPTION

This class describes networked hosts. Currently four OS varieties are supported. They are FreeBSD, OpenBSD, SunOS (Solaris) and Linux.


PROPERTIES AND METHODS

Constructors

new()
Returns an empty Host object

load(FILEHANDLE)
creates a new object and loads its data from the open file handle FILEHANDLE. Reads data until a line containing 'USER' by itself is encountered

thisHost()
Returns a Host object representing the host the framework is running on. The first Host object instantiated in any run of the framework instantiates a special Host object from the data found in the file <CONFIG>/this_host and loads it into the thisHost()property.

Properties

name()

The object's hostname.
aliases()
The object's hostname aliases

ip()
The object's IP address in dotted decimal

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()
The object's hardware architecture as returned by 'uname -m'

upreserve()
Returns a reference to an array containing a list of uids and/or usernames to preserve when generating a password file for this host. Entries in the User database that match one of these values will not be used. The host's current password database will be searched for entries matching these names and or id's. Any matching entries will be preserved in password files produced.

usermap()
Returns a reference to a hash containing pairs of usernames or uids. If a key in the hash is found in the user list when generating a password database for this host, then it will be replaced with its corresponding hashed value. in this way a user named 'jill' in the user database could be called 'jane' on this host.

Set the value by passing either a hashref as described above, or a colon separated list of key=value pairs in a string.

gpreserve()
Returns a reference to an array containing a list of gids and/or group names to preserve when generating a group file for this host. Entries in the Group database that match one of these values will not be used. The host's current group file will be searched for entries matching these names and or id's. Any matching entries will be preserved in the group file produced.

groupmap()
Returns a reference to a hash containing pairs of group names or gids. If a key in the hash is found in the group list when generating a group file for this host, then it will be replaced with its corresponding hashed value. in this way a group named 'wheel' in the group database could be called 'root' on this host.

Set the value by passing either a hashref as described above, or a colon separated list of key=value pairs in a string.

amtype()
Either ``amd'' or ``autofs''

rp()
Responsible Person``. Who to blame.

sshkey()
The path to the root user's ssh key. This is used on hosts that will be driving the Unix::Sysadmin:: framework.


=item validsortorders()

get the fields that User records may be sorted by. These are:

        byHostname
        byOs

defaultsortorder()
    This returns 'byHostname'
cmd(TOKEN) or cmd(TOKEN,VALUE)
The first form returns the path to the Unix command represented by TOKEN. See the Unix::Sysadmin::Cmds manpage for a list of commands. Example:
  $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.)

file(TOKEN) or file(TOKEN,VALUE)
The first form returns the path to the Unix file represented by TOKEN. See the Unix::Sysadmin::Files manpage for a list of files. Example:
  $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.)

Methods

dump()
Print the object to stdout.

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.


SEE ALSO

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

the usatest manpage

the usabackup manpage

the usaupdate manpage

the usapush manpage


AUTHOR

Howard Owen <hbo@egbok.com> =cut