Archive

Archive for 24 January 2009

Using options in Perl programs (with Getopt)

24 January 2009 ddouthitt Leave a comment

The utility getopt (or getopts) gets command line parameters for your program. The bash and ksh shells come with getopt builtin; getopts is a separate program.

To use this capability from Perl, use the Getopt library: either Getopt::Std or Getopt::Long. Most of the time you’ll probably want to use Getopt::Long just for its flexibility.

To start using Getopt::Std, use something like this initial fragment:

use Getopt::Std;
%options=();
getopts("vs:i",\%options);

This will give you the options -v, -i, and -s arg. After this fragment executes, the associated hash table entries will be defined if the argument is present – and if it is present, the value will be either 1 or the argument given. For example, $options{v} might be set to 1, and $options{s} could be "arg".

Using Getopt::Long isn't much more difficult:

use Getopt::Long;
Getoptions("s" => \$sflag,
"verbose!" => \$verbose,
"file=s" => \$file,
"interval=i" => \$interval,
"auto:i" => \$auto)

This set of options shows most of the features of Getoptions(). The -verbose option is a toggle (as noted by the '!' at the end of the option name), and the alternate can be specified as -noverbose. For the -file option, a string argument is required (specified by the '=s' on the end of the option specification). The '=i' (as exemplified by the -interval option) means that an integer argument is required, and the ':i' for the -auto option means a integer argument is optional. Float values (real numbers) are also possible by using the 'f' flag (such as "real=f" - option -real requiring a float argument).

The kconfig utility (HP-UX)

24 January 2009 ddouthitt Leave a comment

The kconfig utility is a utility which allows you to save a complete set of kernel tunables, ready for use in configuring other systems or in returning to an older configuration. These kernel configurations can be saved, copyed, deleted, and restored using the kconfig utility.

For example, consider a HP-UX virtual machine host that was pressed into service early as a general host. How to return to the original installation kernel configuration? Use the original configuration automatically created during installation, “last_install”.

For another example, consider a host configured for the applications you use. Save the configuration and it can be replicated elsewhere with a single command and perhaps a reboot.

For a current list, use the kconfig command by itself:


# kconfig
Configuration Title
backup Automatic Backup
ivm Virtual Machine Configuration
last_install Created by last OS install

The kernel configuration can be exported to a file:

# kconfig -e ivm ivm.txt

…and later imported (possibly on a new machine):

# kconfig -i ivm.txt

The current configuration can be saved to a particular name (such as ivm):

# kconfig -s ivm

All of the usual manipulations are possible, as mentioned before: copy, delete, rename, save, load, and so forth. The manual page is kconfig(1m) and should be available on your HP-UX 11i v2 or v3 system.

Categories: HP-UX, Tips, Tuning Tags: , ,