Assisting the Command Line
piktc will remotely execute, across as many systems as you specify, any arbitrary command string, even command strings referencing PIKT macros.
To see, for example, which of your (up) systems are currently running the portmapper, you might issue the command
# piktc -xv +C "=psall | =egrep 'portmap|rpcbind'" -H downsys
where =psall is defined (in the piktmaster macros.cfg file) as
psall
#if linux
=ps aux
#elsif solaris | hpux
=ps -ef
#elsif sunos
=ps -aux
...
#endif
=ps and =egrep would be defined with the appropriate command path for each operating system, for example, for SuSE Linux:
...
egrep /bin/egrep
...
ps /bin/ps
...
Output from the previous piktc command might then be
processing cadiz...
executing command(s)...
daemon 150 0.0 0.0 1104 0 ? SW Oct 25 0:00 (portmap)
"/bin/ps -aux | /usr/bin/egrep 'portmap|rpcbind'" executed
processing bucharest...
executing command(s)...
root 87 1 0 12:06:23 ? 0:00 /usr/sbin/rpcbind
"/bin/ps -ef | /usr/bin/egrep 'portmap|rpcbind'" executed
processing trondheim...
executing command(s)...
bin 1319 0.0 0.0 1524 128 ? S Sep30 0:00 /sbin/portmap
"/bin/ps aux | /bin/egrep 'portmap|rpcbind'" executed
...
As another example, suppose we need to check /tmp usage across all of our (up) systems. We might run the command
# piktc -x +C "=hostname; =dfk /tmp" -H downsys
which then outputs
kiev0
Filesystem kbytes used avail capacity Mounted on
/dev/sd0e 993006 17 893689 0% /tmp
kiev
Filesystem kbytes used avail capacity Mounted on
swap 769096 296 768800 1% /tmp
ottawa
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/hda8 4150700 128044 3811808 4% /tmp
...
The =dfk macro automatically resolves, per the operating system on the target machine, to the (path and) command options giving us the desired consistent display (for example, to "/bin/df", "/bin/df -k", or "/bin/bdf").
'piktc -x +C "<command string(s)> +H <hosts>"' is therefore sort of an intelligent, macro-aware replacement for ssh'ing commands to run on remote systems. It is extremely handy at sites running more than one operating system or operating system variant, for through the magic of PIKT macros the identical macro command string works the appropriate way everywhere.
'piktc -x' executes commands and waits for their conclusion. Another variant, 'piktc -X', executes commands with no wait. So, for example, you might restart the syslogd everywhere with
# piktc -X +C "=syslog_restart" +H all
(where =syslog_restart is a macro defined as "/etc/init.d/syslog restart" or perhaps something else, depending on the operating system).
With perhaps the simplest but still useful PIKT setup imaginable--the piktc binary and a systems.cfg file--you can maintain custom system lists, whether for referencing within other programs, as in this Perl statement
@hpsys = `piktc -L +H hpux -H downsys`;
or for command-line work, as in a command loop we might use to upgrade Solaris PIKT binaries:
# for sys in `piktc -L +H solaris -H piktdevsys no_usr_local downsys`
> do
> echo $sys
> ssh $sys "/pikt/lib/programs/svcstart.pl -k;
cp /pikt/bin/pikt* /pikt/bin/bak;
cp /usr/local/pikt/bin/solaris/pikt* /pikt/bin;
/pikt/lib/programs/svcstart.pl -r"
> done
It deserves emphasis: PIKT has much to offer, in its totality perhaps too much for your limited needs. In that case, just pick and choose among its many functionalities. If all you need is for PIKT to supply you with system lists to use at the command line or within other programs, that's fine and good enough. See the Partial Configurations section of the PIKT Reference for more on this point.
|