Unix::Sysadmin::Utility - Utility class for the Unix::Sysadmin framework


 use Unix::Sysadmin::Host;
 $hut = Unix::Sysadmin::Utility->new();
 returns a ne Utility object


This class is a catchall for various methods used by the rest of the Unix::Sysadmin framework.


tmpfile({ FROMFILE=<template file name>, PRESERVE=<1|0> } )

Returns a newly opened temp file in the framework's scratch directory. Takes two optional parameters. If the FROMFILE parameter is given, bases the tmp file name on FROMFILE, otherwise uses tmp as the base name. If the PRESERVE parameter is present and non-zero, preserves the file between runs of the framework. Otherwise the file is unlinked when the framework exits.

lock("lock1","lock2"... "lockn")

Locks the components ``lock1'', :lock2`` .. ''lockn`` by attempting to create a hard link to a file called ''lockn.linkme`` in the framework's scratch directory. First checks to see if the linkme file exists and creates it if it doesn't. Returns true (1) if the link(s) succeed(s) and internally caches the results. When the last Utility object goes out of scope, the package destructor cleans up these locks. Lock names should be things like ''Automount``, ''Group``, ''Host``, ''Netgroup`` and ''User`` to control access to the respective databases. This method does not actually constrain the lock names to be anything in particular, but the utility programs use the above convention.

unlock("lock1","lock2"... "lockn")

Checks the internal lock cache and removes the named locks if they exist. You do not need to call this method since the package destructor will clean things up. It's provided in case you want to implement finer grained locking for a long running process.


Pads a passed string with real tab (``\t'') characters to fill #ntabs tab stops of width #tablen. First two parameters are mandatory. The #tablen parameter defaults to 8 if not given.


Uses Net::Ping to send two ICMP echo requests to the host hostname. Returns true if hostname responds, false otherwise. hostname is the name of a host, not a Host object.


Uses Net::Telnet to connect to port 22 (ssh1) on the host hostname Returns true if hostname responds, false otherwise. hostname is the name of a host, not a Host object.


Uses Expect::, /usr/local/bin/ssh and the ssh key given in sshkey to attempt to log on to the host given in hostname using ssh. Returns true (1) if the attempt times out after three seconds (possibly indicating success). Returns false (0) if the connection attempt receives any of the followinf strings:

``Permission Denied''
The answering sshd refused access with the given key.

The answering sshd does not permit root to login.

The answering sshd refused access with the given key, but would allow access with a password.

-head2 sortable_date(time_value)

Returns a date in the form YYYYMMDDHHMMSS, which should be sortable with a numerical sort. If the time_value is given, it is interpreted as a system time (seconds since the epoch) as returned by time() function, and used for the returned date string. Otherwise the current system time is used.


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


Howard Owen <> =cut