Posts By :

Roderick Derks

HPUX Veritas Netbackup 150 150 Roderick Derks

HPUX Veritas Netbackup

1         Inleiding

 

Klein beetje uitleg over commando’s en configuratie instellingen (hoofdlettergevoelig!).

 

 

 

2         Config

 

ELITIL2 : /usr/openv/netbackup : # cat bp.conf

SERVER = ezhbackup01

SERVER = ezhbackup02

CLIENT_NAME = ELITIL2

EMMSERVER = ezhbackup01

MEDIA_SERVER = ezhbackup02

MEDIA_SERVER = ELITIL2

SERVER_SENDS_MAIL = YES

USE_VXSS = PROHIBITED

 

ELITIL2 : /usr/openv/netbackup : # cat /usr/openv/volmgr/vm.conf

MM_SERVER_NAME = ELITIL2

 

 

3         Comando’s

 

# stoppen en starten client/server

cd /usr/openv/netbackup/bin

bp.kill_all

bp.start_all   (= volgens mij ook goed voor een herstart, scheelt een hoop tijd)

 

# commando om te checken of de backup gelopen heeft

 

/usr/openv/netbackup/bin/admincmd/bpdbjobs -summary -L

 

ELITIL2 : /phit/bin : # mincmd/bpdbjobs -summary -L                          <

Summary of jobs on ezhbackup01.elisabeth.nl

Queued:                                9

Waiting-to-Retry:                        0

Active:                           6

Successful:                    1260

Partially Successful:           190

Failed:                           8

Incomplete:                       0

Suspended:                        0

Total:                         1473

 

Dit is echter niet iets waar we mee kunnen zien of de backups voor ELITIL2 daadwerkelijk lopen.

 

Ik kan ook bpdbjobs -report doen en dan zie ik wat meer.

 

 

4         PACS backups

 

De backups worden dagelijks opgestart op ELITIL2 met behulp van crontab entries:

 

ELITIL2 : /phit/bin : # crontab -l|grep DB

30 2 * * * /phit/bin/DBBackup > /phit/log/DBBackup.log 2>&1

ELITIL2 : /phit/bin : # crontab -l|grep Day

# Daybackup for the PACS system

35 2 * * * /phit/bin/Daybackup > /phit/log/Daybackup.log 2>&1

 

In DBBackup en Daybackup zien we de volgende policy:

 

/usr/openv/netbackup/bin/bpbackup -p HPUX_PACS -s Full-Daily /isfs*/$YEAR/

$MONTH

 

 

Als ik dan bpdbjobs -report|grep -i HPUX_PACS uitvoer, zou je iets terug moeten zien:

 

ELITIL2 : /phit/bin : # bpdbjobs -report|grep -i HPUX_PACS

 

5         Installatie op HPUX

 

 

5.1        software

 

Onderdelen: veritas netbackup server en client

Benodigheden: beide packages, 6.5.1 terug te vinden op de EZHBACKUP01 of te downloaden op de Veritas website. Client 6.5.1 terug te vinden in de file \\ezhbackup01\d$\Source\NBU 6.5.1\Linux_and_HP\ NB_CLT_6.5.1.Linux_HPUX_Client.tar.

 

Haal ook de scripts die in de tar file staan. Voor de client:

VrtsNB_CLT_6.5.1.postinstall

VrtsNB_CLT_6.5.1.postuninstall

VrtsNB_CLT_6.5.1.preinstall

NB_update.install

VrtsNB_CLT_6.5.1.README (ja ook de README)

 

Zorg dat het er zo uitziet, ook execute rechten voor alle scripts:

 

[ELITIL] ELITIL2I: /phit/tmp/NB # ls -al

total 585496

drwxr-xr-x   2 root       sys           1024 Mar 27 13:49 .

drwxrwxrwx   3 root       sys           1024 Mar 27 12:10 ..

-rwxr-xr-x   1 root       bin         101972 Nov 16 20:09 NB_update.install

-rw-r–r–   1 root       bin           6380 Nov 13 23:59 VrtsNB_6.5.1.README

-rw-r–r–   1 root       bin        201638524 Nov 21 18:21 VrtsNB_6.5.1.hpia64.tar.Z

-rwxr-xr-x   1 root       bin          12087 Nov 21 18:44 VrtsNB_6.5.1.postinstall

-rwxr-xr-x   1 root       bin          12087 Nov 21 18:44 VrtsNB_6.5.1.postuninstall

-rwxr-xr-x   1 root       bin          12087 Nov 21 18:44 VrtsNB_6.5.1.preinstall

-rwxr-xr-x   1 root       bin          12087 Nov 21 18:44 VrtsNB_6.5.1.preuninstall

-rw-r–r–   1 root       sys        97927186 Nov 16 19:38 VrtsNB_CLT_6.5.1.HP-UX-IA64.tar.Z

-rw-r–r–   1 root       sys          10051 Nov 13 23:59 VrtsNB_CLT_6.5.1.README

-rwxr-xr-x   1 root       sys           9164 Nov 16 20:12 VrtsNB_CLT_6.5.1.postinstall

-rwxr-xr-x   1 root       sys           9164 Nov 16 20:12 VrtsNB_CLT_6.5.1.postuninstall

-rwxr-xr-x   1 root       sys           9164 Nov 16 20:12 VrtsNB_CLT_6.5.1.preinstall

 

Installatie starten met:

[ELITIL] ELITIL2I: /phit/tmp/NB # ./NB_update.install

 

Latere updates die zijn geinstalleerd:

VrtsNB_6.5.1.hpia64.tar.Z
VrtsNB_CLT_6.5.1.HP-UX-IA64.tar.Z
NB-Java.tar.Z

VrtsNB_CLT_6.5.2.Linux-IA64.tar.Z (NB_CLT_6.5.2_305647.tar)
VrtsNB_6.5.2A.hpia64.tar.Z (NB_6.5.2A.hpia64_305662.tar)

 

Let op: iedere update genereert voor een rollback scenariofiles in /usr/openv/pack. De grootte van de files kan oplopen tot vele honderden Mb’s tot meer dan een gigabyte. Als het filesysteem volzit akn er geen update meer plaatsvinden.

 

Toevoegen aan de Netbackup configuratie:

[ELITIL] ELITIL2I: /usr/openv/netbackup/bin/admincmd # nbemmcmd -addhost -machinename ELITIL2I -machinetype media -masterserver ezhbackup01 operatingsystem hpux -netbackupversion 6.5

 

5.2        License keys

 

Keys I added to get this list you see down here:

 

AJX6-UR6N-9RIE-ONC8-38PP-8PRP-PRR6-PPP

BJX6-CPWU-8WFD-RPP6-PPPP-NWPP-3PPO-PP

AJX6-JR3D-KNN9-8PZ3-NO4P-PPPP-PPPP-PPP

 

 

ELITIL2 : /usr/openv/netbackup/bin/admincmd : # get_license_key

 

        License Key Utility

        ——————-

 

        A) Add a License Key

        D) Delete a License Key

        F) List Active License Keys

        L) List Registered License Keys

        H) Help

        q) Quit License Key Utility

 

 

Enter a letter: F

 

Enter the name of the host (default is ELITIL2I):

 

Active NetBackup Features

=========================

 

License Key:    BJX6-CPWU-8WFD-RPP6-PPPP-NWPP-3PPO-PP

Date Added:     Mar 27, 2008 at 15:24:07

Host:           ELITIL2i

Product:        NetBackup Enterprise Server

Client count:   See license certificate.

Expires:        No Expiration Date

Feature:        Base NetBackup

 

License Key:    AJX6-UR6N-9RIE-ONC8-38PP-8PRP-PRR6-PPP

Date Added:     Mar 27, 2008 at 15:22:27

Host:           ELITIL2i

Product:        NetBackup Enterprise Server

Client count:   See license certificate.

Expires:        No Expiration Date

Feature:        Base NetBackup

 

License Key:    AJX6-JR3D-KNN9-8PZ3-NO4P-PPPP-PPPP-PPP

Date Added:     Mar 27, 2008 at 15:28:30

Host:           ELITIL2i

Product:        NetBackup Enterprise Server

Client count:   See license certificate.

Expires:        No Expiration Date

Feature:        Shared Storage Option

 

License Key:    BJX6-CPWU-8WFD-RPP6-PPPP-NWPP-3PPO-PP

Date Added:     Mar 27, 2008 at 15:24:07

Host:           ELITIL2i

Product:        NetBackup Enterprise Server

Client count:   See license certificate.

Expires:        No Expiration Date

Feature:        Intelligent Disaster Recovery

Feature:        Open File Backup – deprecated

 

License Key:    AJX6-UR6N-9RIE-ONC8-38PP-8PRP-PRR6-PPP

Date Added:     Mar 27, 2008 at 15:22:27

Host:           ELITIL2i

Product:        NetBackup Enterprise Server

Client count:   See license certificate.

Expires:        No Expiration Date

Feature:        Open File Backup – deprecated

Feature:        Snapshot Client <Core Frozen Image Services>

 

License Key:    BJX6-CPWU-8WFD-RPP6-PPPP-NWPP-3PPO-PP

Date Added:     Mar 27, 2008 at 15:24:07

Host:           ELITIL2i

Product:        NetBackup Enterprise Server

Client count:   See license certificate.

Expires:        No Expiration Date

Feature:        StorageTek ACS Robotic Libraries

 

License Key:    AJX6-UR6N-9RIE-ONC8-38PP-8PRP-PRR6-PPP

Date Added:     Mar 27, 2008 at 15:22:27

Host:           ELITIL2i

Product:        NetBackup Enterprise Server

Client count:   See license certificate.

Expires:        No Expiration Date

Feature:        StorageTek ACS Robotic Libraries

 

License Key:    BJX6-CPWU-8WFD-RPP6-PPPP-NWPP-3PPO-PP

Date Added:     Mar 27, 2008 at 15:24:07

Host:           ELITIL2i

Product:        NetBackup Enterprise Server

Client count:   See license certificate.

Expires:        No Expiration Date

Feature:        Fujitsu LMF Robotic Libraries

 

License Key:    AJX6-UR6N-9RIE-ONC8-38PP-8PRP-PRR6-PPP

Date Added:     Mar 27, 2008 at 15:22:27

Host:           ELITIL2i

Product:        NetBackup Enterprise Server

Client count:   See license certificate.

Expires:        No Expiration Date

Feature:        Fujitsu LMF Robotic Libraries

 

License Key:    BJX6-CPWU-8WFD-RPP6-PPPP-NWPP-3PPO-PP

Date Added:     Mar 27, 2008 at 15:24:07

Host:           ELITIL2i

Product:        NetBackup Enterprise Server

Client count:   See license certificate.

Expires:        No Expiration Date

Feature:        IBM ATL Robotic Libraries

 

License Key:    AJX6-UR6N-9RIE-ONC8-38PP-8PRP-PRR6-PPP

Date Added:     Mar 27, 2008 at 15:22:27

Host:           ELITIL2i

Product:        NetBackup Enterprise Server

Client count:   See license certificate.

Expires:        No Expiration Date

Feature:        IBM ATL Robotic Libraries

 

License Key:    BJX6-CPWU-8WFD-RPP6-PPPP-NWPP-3PPO-PP

Date Added:     Mar 27, 2008 at 15:24:07

Host:           ELITIL2i

Product:        NetBackup Enterprise Server

Client count:   See license certificate.

Expires:        No Expiration Date

Feature:        ADIC DAS/SDLC Robotic Libraries

 

License Key:    AJX6-UR6N-9RIE-ONC8-38PP-8PRP-PRR6-PPP

Date Added:     Mar 27, 2008 at 15:22:27

Host:           ELITIL2i

Product:        NetBackup Enterprise Server

Client count:   See license certificate.

Expires:        No Expiration Date

Feature:        ADIC DAS/SDLC Robotic Libraries

 

License Key:    BJX6-CPWU-8WFD-RPP6-PPPP-NWPP-3PPO-PP

Date Added:     Mar 27, 2008 at 15:24:07

Host:           ELITIL2i

Product:        NetBackup Enterprise Server

Client count:   See license certificate.

Expires:        No Expiration Date

Feature:        Microsoft RSM Robotic Libraries

 

License Key:    AJX6-UR6N-9RIE-ONC8-38PP-8PRP-PRR6-PPP

Date Added:     Mar 27, 2008 at 15:22:27

Host:           ELITIL2i

Product:        NetBackup Enterprise Server

Client count:   See license certificate.

Expires:        No Expiration Date

Feature:        Microsoft RSM Robotic Libraries

 

License Key:    BJX6-CPWU-8WFD-RPP6-PPPP-NWPP-3PPO-PP

Date Added:     Mar 27, 2008 at 15:24:07

Host:           ELITIL2i

Product:        NetBackup Enterprise Server

Client count:   See license certificate.

Expires:        No Expiration Date

Feature:        Remote Media Server Support

 

License Key:    AJX6-UR6N-9RIE-ONC8-38PP-8PRP-PRR6-PPP

Date Added:     Mar 27, 2008 at 15:22:27

Host:           ELITIL2i

Product:        NetBackup Enterprise Server

Client count:   See license certificate.

Expires:        No Expiration Date

Feature:        Remote Media Server Support

 

License Key:    BJX6-CPWU-8WFD-RPP6-PPPP-NWPP-3PPO-PP

Date Added:     Mar 27, 2008 at 15:24:07

Host:           ELITIL2i

Product:        NetBackup Enterprise Server

Client count:   See license certificate.

Expires:        No Expiration Date

Feature:        Robotic Library Sharing Support

 

License Key:    AJX6-UR6N-9RIE-ONC8-38PP-8PRP-PRR6-PPP

Date Added:     Mar 27, 2008 at 15:22:27

Host:           ELITIL2i

Product:        NetBackup Enterprise Server

Client count:   See license certificate.

Expires:        No Expiration Date

Feature:        Robotic Library Sharing Support

 

License Key:    BJX6-CPWU-8WFD-RPP6-PPPP-NWPP-3PPO-PP

Date Added:     Mar 27, 2008 at 15:24:07

Host:           ELITIL2i

Product:        NetBackup Enterprise Server

Client count:   See license certificate.

Expires:        No Expiration Date

Feature:        Remote Client Support

Feature:        Open File Backup

 

License Key:    AJX6-UR6N-9RIE-ONC8-38PP-8PRP-PRR6-PPP

Date Added:     Mar 27, 2008 at 15:22:27

Host:           ELITIL2i

Product:        NetBackup Enterprise Server

Client count:   See license certificate.

Expires:        No Expiration Date

Feature:        Open File Backup

 

=========================

 

 

 

5.3        Kernel parameters aanpassen

Om de tapedrives te kunnen benaderen:

 

[ELITIL] ELITIL2I:  ioscan -f reports:
Class I H/W Path Driver S/W State H/W Type Description
==================================================================
=============
unknown -1 0/2/1/0/4/0.45.3.255.5.5.0 UNCLAIMED UNKNOWN HP Ultrium 3-SCSI

 

Hier is stape not loaded as static.

Ga naar: sam -> kernel_configuration -> modules
Verander stape naar static.

 

Reboot noodzakelijk.

vmware esx commands 150 150 Roderick Derks

vmware esx commands

Connect a virtual switch to an adapter:
# esxcfg-vswitch -L vmnic2 vSwitch0

Perl using hash variables 150 150 Roderick Derks

Perl using hash variables

In Perl, a hash lets you create a one-to-one association between a variable, called the key, and a value. We’ll show you the basics of Perl hashes and some useful tricks.

One of the most useful constructs in Perl is the humble array, which lets you store more than one value in a single variable. This is very useful if you have a set of related values—for example, a shopping list—and you need to group them into a collection, yet be able to access them individually.

A variant of the regular array, which is indexed by number, is the hash or associative array, which is indexed by key. A hash is a Perl construct that allows a programmer to create one-to-one associations between a variable, or “key,” and its value. Elements of a hash can be accessed only via their keys, and keys within a hash must be unique.

Get ready, because we’re about to give you a crash course in how Perl hashes work. And we’ll show you some examples of where you can use them.

Hash basics
Creating a Perl hash is very similar to defining an array: You create a hash variable and (optionally) assign some keys and values to it:
# define hash
%account = (‘username’ => ‘jimmyboy’, ‘password’ => ‘scar3me’);

Notice the % symbol preceding the variable name, and contrast it to the @ sign preceding an array. Notice also the => symbol, which is used to connect a key to its associated value.

Hash elements consist of a key-value pair. Each key in a hash is unique and serves as a unique identifier for the corresponding value. The value can be retrieved only if you know the corresponding key. Therefore, in the example above, you would retrieve the value jimmyboy with the following notation:
# retrieve value of hash element
print $account{‘username’};

To add new elements to a hash, define a new key-value pair, and Perl will automatically add it to the hash variable:
# add an element to a hash
$account{‘active’} = 1;
 
# the hash now contains
%account = (‘username’ => ‘jimmyboy’, ‘password’ => ‘scar3me’, ‘active’ => 1);

Note that unlike arrays, Perl hashes are not arranged in any specific numerical order or in the order in which the keys are added. Rather, Perl uses its own sorting algorithms to arrange the elements in an optimal manner. For this reason, you must always access hash values by key rather than position.

To remove an element from a hash, use the delete() function as shown below. Don’t even think about using the infamous—and flawed—technique of assigning an empty value to the key. That just leaves the key in the array with a null value. It doesn’t actually remove the key, which is why you need to use delete() instead.
# delete the named key from the hash
delete($account{‘password’});

Hashes and regular arrays mix well with each other, so it’s even possible to have a hash key pointing to an array (or vice versa), as in this example:
# hash keys pointing to an array
%combo = (‘colors’ => [‘red’, ‘green’, ‘blue’], ‘vowels’ => [‘a’, ‘e’, ‘i’, ‘o’, ‘u’]);

Processing hash elements
Perl offers the keys() and values() functions to obtain lists of all the keys and values present in a hash. These functions come in handy when you need to process all the elements in a hash using a foreach() loop. The following example iterates over a hash and writes the elements to a file as comma-separated key-value pairs.
# set up hash
%capitals = (‘china’ => ‘beijing’, ‘england’ => ‘london’, ‘france’ => ‘paris’, ‘norway’ => ‘oslo’, ‘italy’ => ‘rome’);
 
# open file
open (FILE, “>data.txt”);
 
# process hash elements
# write to file in csv format
foreach $k (keys (%capitals))
{
        print FILE $k, “,”, $capitals{$k}, “\n”;
}
 
# close file
close(FILE);

Note that the keys() function returns an array. By iterating over this array in a foreach() loop, it becomes possible to process each and every element in the hash.

Another option is to use the each() function, which iteratively moves through a hash creating a two-item array at each stage for the current key and value. The each() function is thus well suited to a while() loop, as illustrated in this rewrite of the previous example:
# set up hash
%capitals = (‘china’ => ‘beijing’, ‘england’ => ‘london’, ‘france’ => ‘paris’, ‘norway’ => ‘oslo’, ‘italy’ => ‘rome’);
 
# open file
open (FILE, “>data.txt”);
 
# process hash elements
# write to file in csv format
while ( ($country, $capital) = each (%capitals))
{
       print FILE $country, “,”, $capital, “\n”;
}
 
# close file
close(FILE);

Quick tip: If all you really want to do is check if a particular value exists in a hash, don’t waste time by using a loop and an if() test at each iteration. Instead, use the built-in exists() function, which returns Boolean true if a key match occurs.

 

One-Dimension Array Operations

Create an empty array:
@myarray = ( );

Create a filled array:
@myarray = ($var0, $var1, $var2, …);

Get the length of an array:
$arrlen = @myarray;
or
$arrlen = $#myarray + 1;

Fetch a specific single member in an array:
$myscalar = $myarray[$index];

Fetch a contiguous set of members in an array (‘ .. ‘ is literal):
@newarray = @myarray[$idx_beg .. $idx_end];

Fetch specific members in an array:
@newarray = @myarray[$idx1, $idx2, $idx3, …];

Set a specific single member in an array:
$myarray[$index] = $myscalar;

Set a contiguous set of members in an array (‘ .. ‘ is literal):
@myarray[$idx_beg .. $idx_end] = @replac;

Set specific members in an array:
@myarray[$idx1, $idx2, $idx3, …] = @replac;

Remove but save the scalar from the beginning of an array:
$value = shift (@myarray);

Insert a scalar at the beginning of an array (returns new size):
$newlen = unshift (@myarray, $myvar);

Insert one array at the beginning of another existing one (returns new size):
$newlen = unshift (@another, @one_array);

Remove but save the scalar at the end of an array:
$value = pop (@myarray);

Add a value at the end of an array (returns new size):
$newlen = push (@myarray, $myvar);

Append one array to another existing one (returns new size):
$newlen = push (@another, @one_array);

Delete everyting from an array and lose it all:
%myarray = ();

Delete everyting from an array but save it for later:
@rem_data = splice (@myarray);

Delete everything from a specified position and later:
@rem_data = splice (@myarray,$first_del);
pop (@myarray);    is same as    splice (@myarray, -1);

Delete several elements from a specified position and later:
@rem_data = splice (@myarray, $first_del, $num_dels);
pop (@myarray);    is same as    splice (@myarray, $#myarray, 1);
shift (@myarray);    is same as    splice (@myarray, 0, 1);

Delete several elements from a specified position and later, then replace with data from a list:
@rem_data = shift (@myarray, $first_del, $num_dels, $replac1, $replac2, …);
or
@rem_data = shift (@myarray, $first_del, $num_dels, @replac);

Multi-Dimension Arrays

In a 2-dimension array, the first dimension is a set of references to arrays, and each reference yields a 1-D array of scalar values for the second dimension. In a 3-D array, the first and second dimensions are sets of references to arrays, and the last dimension is a set of scalar values.

Create a filled 2-D array (2r x 3c):
@veca = {[$r0c0,$r0c1], [$r1c0,$r1c1], [$r2c0,$r2c1]};

Fill in a single row from another 1-D array:
$veca[$rownum] = [ @row ];

Fetch a single row:
@row = @{$veca[$rownum]};
or
@row = @$veca[$rownum];

Fetch a single member:
$val = ${$veca[$rownum]}->[$colnum];
or
$val = $veca[$rownum]->[$colnum];
or
$val = $veca[$rownum][$colnum];

Number of rows (length of the first dimension):
@n_rows = $#veca + 1;

Number of columns in a row:
@n_cols = $#{$veca[$rownum]};

Hash Operations

Create an empty hash:
%myhash = { };

Create a filled hash:
%myhash = ($key1, $val1, $key2, $val2, …);
or
%myhash = ($key1 => $val1, $key2 => $val2, …);

Fetch a hash value from a known key:
$the_val = $myhash{$the_key};

Fetch a several hash values at once
@val_list = @myhash{$key1, $key2, $key3, …};

Create a reference to an anonymous filled hash:
$hashref = {$key1 => $val1, $key2 => $val2, …};
for example
$record[$rec_num] = {name => $val1, rank => $val2, sernum => $val3};
then
$this_rank = $record[$this_rec_num]->{‘rank’};

Test if a particular key exists in a hash:
$is_there = exists ($myhash{$the_key});

Test if a particular key has its corresponding value defined (not undef):
$has_value = defined ($myhash{$the_key});

Get a list of all keys:
@keylist = keys (%myhash);

Get a list of all values (same order as keys):
@valuelist = values (%myhash);

Remove a key/value pair but save it elsewhere for later:
%removed = delete ($myhash{$delkey});

 

 

Manipulating Perl Arrays

How to perform tasks with an array in Perl

Now that you have seen the basics of arrays, you’ll want to see how to change and manipulate an array or the elements of an array. The first thing we will look at is changing and adding elements.

Changing & Adding Elements

To change an array element, you can just access it with its list number and assign it a new value:

@browser = (“NS”, “IE”, “Opera”);
$browser[2]=”Mosaic”;

This changes the value of the element with the list number two (remember, arrays start counting at zero- so the element with the list number two is actually the third element). So, we changed “Opera” to “Mosaic”, thus the array now contains “NS”, “IE”, and “Mosaic”.

Now, suppose we want to add a new element to the array. We can add a new element in the last position by just assigning the next position a value. If it doesn’t exist, it is added on to the end:

@browser = (“NS”, “IE”, “Opera”);
$browser[3]=”Mosaic”;

Now, the array has four elements: “NS”, “IE”, “Opera”, and “Mosaic”.

Splice Function

Using the splice function, you can delete or replace elements within the array. For instance, if you simply want to delete an element, you could write:

@browser = (“NS”, “IE”, “Opera”);
splice(@browser, 1, 1);

You’ll see three arguments inside the () of the splice function above. The first one is just the name of the array you want to splice. The second is the list number of the element where you wish to start the splice (starts counting at zero). The third is the number of elements you wish to splice. In this case, we just want to splice one element. The code above deletes the element at list number 1, which is “IE” (NS is zero, IE is 1, Opera is 2). So now the array has only “NS” and “Opera”.

If you want to delete more than one element, change that third number to the number of elements you wish to delete. Let’s say we want to get rid of both “NS” and “IE”. We could write:

@browser = (“NS”, “IE”, “Opera”);
splice(@browser, 0, 2);

Now, it starts splicing at list number zero, and continues until it splices two elements in a row. Now all that will be left in the array is “Opera”.

You can also use splice to replace elements. You just need to list your replacement elements after your other three arguments within the splice function. So, if we wanted to replace “IE” and “Opera” with “NeoPlanet” and “Mosaic”, we would write it this way:

@browser = (“NS”, “IE”, “Opera”);
splice(@browser, 1, 2, “NeoPlanet”, “Mosaic”);

Now the array contains the elements “NS”, “NeoPlanet”, and “Mosaic”. As you can see, the splice function can come in handy if you need to make large deletions or replacements.

Unshift/Shift

If you want to simply add or delete an element from the left side of an array (element zero), you can use the unshift and shift functions. To add an element to the left side, you would use the unshift function and write something like this:

@browser = (“NS”, “IE”, “Opera”);
unshift(@browser, “Mosaic”);

As you can see, the first argument tells you which array to operate on, and the second lets you specify an element to be added to the array. So, “Mosaic” takes over position zero and the array now has the four elements “Mosaic”, “NS”, “IE”, and “Opera”.

To delete an element from the left side, you would use the shift function. All you have to do here is give the array name as an argument, and the element on the left side is deleted:

@browser = (“NS”, “IE”, “Opera”);
shift(@browser);

Now, the array has only two elements: “IE” and “Opera”.

You can keep the value you deleted from the array by assigning the shift function to a variable:

@browser = (“NS”, “IE”, “Opera”);
$old_first_element= shift(@browser);

Now the array has only “IE” and “Opera”, but you have the variable $old_first_element with the value of “NS” so you can make use of it after taking it from the array.

Push/Pop

These two functions are just like unshift and shift, except they add or delete from the right side of an array (the last position). So, if you want to add an element to the end of an array, you would use the push function:

@browser = (“NS”, “IE”, “Opera”);
push(@browser, “Mosaic”);

Now, you have an array with “NS”, “IE”, “Opera”, and Mosaic”.

To delete from the right side, you would use the pop function:

@browser = (“NS”, “IE”, “Opera”);
pop(@browser);

Now you have an array with just “NS” and “IE”.

You can keep the value you deleted from the array by assigning the pop function to a variable:

@browser = (“NS”, “IE”, “Opera”);
$last_element= pop(@browser);

Now the array has only “NS” and “IE”, but you have the variable $last_element with the value of “Opera” so you can make use of it after taking it from the array.

Chop & Chomp

If you want to take the last character of each element in an array and “chop it off”, or delete it, you can use the chop function. It would look something like this:

@browser = (“NS4”, “IE5”, “Opera3”);
chop(@browser);

This code would take the numbers off the end of each element, so we would be left with “NS”, “IE” and “Opera”.

If you want to remove newline characters from the end of each array element, you can use the chomp function. This comes in handy later when we are reading from a file, where we would need to chomp the new line (\n) character from each line in a file. Here is a more simplified example for now:

@browser = (“NS4\n”, “IE5\n”, “Opera3\n”);
chomp(@browser);

This code takes off the \n characters from the end of each element, leaving us with NS4, IE5, and Opera3.

Sort

If you want to sort the elements of an array, this can come in handy. You can sort in ascending or descending order with numbers or strings. Numbers will go by the size of the number, strings will go in alphabetical order.

@browser = (“NS”, “IE”, “Opera”);
sort (ascend @browser);

sub ascend
{
 $a <=> $b;
}

The sub from above is a subroutine, much like what is called a “function” in other languages. We will explain that in more detail later. As you can see, the code above would sort in ascending order, so it would sort our array in alphabetical order. So, we have: “IE”, “NS”, and “Opera” as the new order. If you want it in reverse alphabetical order, you would use $b <=> $a in place of the $a <=> $b above. You could change the name of the subroutine to whatever you wish, just be sure you call the subroutine with the same name. This will make a bit more sense after we get to the section on subroutines and reading from files.

Reverse

You can reverse the order of the array elements with the reverse function. You would just write:

@browser = (“NS”, “IE”, “Opera”);
reverse(@browser);

Now, the order changes to “Opera”, “IE”, and “NS”.

Join

You can create a flat file database from your array with the join function. Again, this is more useful if you are reading and writing form files. For now, what you will want to know is that it allows you to use a delimiter (a character of your choice) to separate array elements. The function creates a variable for each element, joined by your delimiter. So, if you want to place a colon (:) between each element, you would write:

@browser = (“NS”, “IE”, “Opera”);
join(“:”, @browser);

This would create something like this:

NS:IE:Opera

Split

The split function is very handy when dealing with strings. It allows you to create an array of elements by splitting a string every time a certain delimiter (a character of your choice) shows up within the string. Suppose we had the string:

NS:IE:Opera

Using the split function, we could create an array with the elements “NS”, “IE”, and “Opera” by splitting the string on the colon delimiter (:). We could write:

$browser_list=”NS:IE:Opera”;
@browser= split(/:/, $browser_list);

Notice in the split function that you place your delimiter between two forward slashes. You then place the string you want to split as the second argument, in this case the string was the value of the $browser_list variable. Setting it equal to @browser creates the @browser array from the split.

Well, that should be enough to keep us all busy for a while. You can do a whole bunch of things with arrays, and we’ll be using them extensively in later sections. So, have fun with what we have so far, we’ll be moving on soon!

Well, that’s it for now. Let’s go on to: Associative Arrays.

 

Perl advanced output overview 150 150 Roderick Derks

Perl advanced output overview

In many situations, especially for web programming, you will find that you want to put certain things, such as backslashes or quotes, in your text that aren’t allowed in a traditional print statements. A statement such as

print "I said "I like mangos and bananas". ";

will not work because the interpreter would think that the quotes mark the end of the string. As with all things in Perl, there are many solutions to this problem.

Use other quotes

The quickest solution to this problem would be to use single quotes to surround the string, allowing the use of double quotes in the middle.

# I said "I like mangos and bananas".
print 'I said "I like mangos and bananas".';

This is obviously not the best solution, as it is conceivable that you are trying to print a string containing both kinds of quote:

# I said "They're the most delicious fruits".
print 'I said "They're the most delicious fruits".';

Escape characters

For situations like the above where only a short amount of text is being quoted, a common solution is to escape any quotes in the string. By preceding any quotes with a backslash they are treated as literal characters.

print "I said \"They\'re the most delicious fruits\".";

This of course implies that you also need to escape any backslashes you want to use in your string. To print the line I have written above literally in perl, you would need to write.

print " print \"I said \\\"They\\\'re the most delicious fruits\\\".\";"

Luckily perl provides us with another way of quoting strings that avoids this problem.

Custom Quotes

Perl provides the operators q and qq that allows you to decide which characters are used to quote strings. Most punctuation characters can be used. Here are a few examples:

print qq{ I said "They're the most delicious fruits!". };
print q! I said "They're the most delicious fruits\!". !;

The only symbols I have found that cannot be used for these quotes are $ ` /

Block Output

As can be seen, while the custom quotes option works for short strings, it can run into problems if a lot of text containing a lot of punctuation is output. For this situation, a technique called Block quoting can be used.

print <<OUTPUT
I said "They're the most delicious fruits!".
OUTPUT;

Any string of characters can be used instead of OUTPUT in the example above. Using this technique anything can be output no matter what characters it contains. The one caveat of this method is that the closing OUTPUT must be the first character on the line, there cannot be any space before it.

print <<EverythingBetween
...
...
EverythingBetween;

Variable Output

It is possible to output variables within strings when you use some of these methods:

my $one = 'mangoes';

print "I like $one."; # I like mangoes.
print 'I like $one.'; # I like $one.
print qq@ I love $one.@; # I love mangoes.
print q#I love $one.#; # I love $one.

print <<OUT
I love $one
OUT; # I love mangoes

print <<'OUT'
I love $one
OUT; # I love $one

Collect data and print it in a nice way on the screen

# this is to create a report that can be printed to the screen or to a file
formline q{@<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @<<<< @<<<<<<<<<<   @>\@<<
}, $mac, $ip, $dns, ${StackTypeNumber}, ${stack_copy}, ${switch}, ${port};
# this is to print the collected statistics to a variable
$rapport = $^A;

This is an internal function used by formats, though you may call it, too. It formats (see the perlform manpage) a list of values according to the contents of PICTURE, placing the output into the format output accumulator, $^A (or $ACCUMULATOR in English). Eventually, when a write() is done, the contents of $^A are written to some filehandle, but you could also read $^A yourself and then set $^A back to “”. Note that a format typically does one formline() per line of form, but the formline() function itself doesn’t care how many newlines are embedded in the PICTURE. This means that the ~ and ~~ tokens will treat the entire PICTURE as a single line. You may therefore need to use multiple formlines to implement a single record format, just like the format compiler.

Be careful if you put double quotes around the picture, because an “@” character may be taken to mean the beginning of an array name. formline() always returns TRUE. See the perlform manpage for other examples.

 

Caveats

The single quote ‘ q{ and double quote ” qq <<A operators, behave differently. Whereas when using double quotes, you can include variables and escape any characters, when you use single quotes you can only escape single quotes and you cannot include variables.

Perl string matching 150 150 Roderick Derks

Perl string matching

Regular expressions

A regular expression is contained in slashes, and matching occurs with the =~ operator. The following expression is true if the string the appears in variable $sentence.

$sentence =~ /the/

The RE is case sensitive, so if

$sentence = "The quick brown fox";

then the above match will be false. The operator !~ is used for spotting a non-match. In the above example

$sentence !~ /the/

is true because the string the does not appear in $sentence.

 


The $_ special variable

We could use a conditional as

if ($sentence =~ /under/)
{
print "We're talking about rugby\n";
}

which would print out a message if we had either of the following

$sentence = "Up and under";
$sentence = "Best winkles in Sunderland";

But it’s often much easier if we assign the sentence to the special variable $_ which is of course a scalar. If we do this then we can avoid using the match and non-match operators and the above can be written simply as

if (/under/)
{
print "We're talking about rugby\n";
}

The $_ variable is the default for many Perl operations and tends to be used very heavily.

 


More on REs

In an RE there are plenty of special characters, and it is these that both give them their power and make them appear very complicated. It’s best to build up your use of REs slowly; their creation can be something of an art form.

Here are some special RE characters and their meaning

.	# Any single character except a newline
^ # The beginning of the line or string
$ # The end of the line or string
* # Zero or more of the last character
+ # One or more of the last character
? # Zero or one of the last character

and here are some example matches. Remember that should be enclosed in // slashes to be used.

t.e	# t followed by anthing followed by e
# This will match the
# tre
# tle
# but not te
# tale
^f # f at the beginning of a line
^ftp # ftp at the beginning of a line
e$ # e at the end of a line
tle$ # tle at the end of a line
und* # un followed by zero or more d characters
# This will match un
# und
# undd
# unddd (etc)
.* # Any string without a newline. This is because
# the . matches anything except a newline and
# the * means zero or more of these.
^$ # A line with nothing in it.

There are even more options. Square brackets are used to match any one of the characters inside them. Inside square brackets a indicates “between” and a ^ at the beginning means “not”:

[qjk]		# Either q or j or k
[^qjk] # Neither q nor j nor k
[a-z] # Anything from a to z inclusive
[^a-z] # No lower case letters
[a-zA-Z] # Any letter
[a-z]+ # Any non-zero sequence of lower case letters

At this point you can probably skip to the end and do at least most of the exercise. The rest is mostly just for reference.

A vertical bar | represents an “or” and parentheses () can be used to group things together:

jelly|cream	# Either jelly or cream
(eg|le)gs # Either eggs or legs
(da)+ # Either da or dada or dadada or...

Here are some more special characters:

\n		# A newline
\t # A tab
\w # Any alphanumeric (word) character.
# The same as [a-zA-Z0-9_]
\W # Any non-word character.
# The same as [^a-zA-Z0-9_]
\d # Any digit. The same as [0-9]
\D # Any non-digit. The same as [^0-9]
\s # Any whitespace character: space,
# tab, newline, etc
\S # Any non-whitespace character
\b # A word boundary, outside [] only
\B # No word boundary

Clearly characters like $, |, [, ), \, / and so on are peculiar cases in regular expressions. If you want to match for one of those then you have to preceed it by a backslash. So:

\|		# Vertical bar
\[ # An open square bracket
\) # A closing parenthesis
\* # An asterisk
\^ # A carat symbol
\/ # A slash
\\ # A backslash

and so on.

 


Some example REs

As was mentioned earlier, it’s probably best to build up your use of regular expressions slowly. Here are a few examples. Remember that to use them for matching they should be put in // slashes

[01]		# Either "0" or "1"
\/0 # A division by zero: "/0"
\/ 0 # A division by zero with a space: "/ 0"
\/\s0 # A division by zero with a whitespace:
# "/ 0" where the space may be a tab etc.
\/ *0 # A division by zero with possibly some
# spaces: "/0" or "/ 0" or "/ 0" etc.
\/\s*0 # A division by zero with possibly some
# whitespace.
\/\s*0\.0* # As the previous one, but with decimal
# point and maybe some 0s after it. Accepts
# "/0." and "/0.0" and "/0.00" etc and
# "/ 0." and "/ 0.0" and "/ 0.00" etc.

 


Get the output from a command and split the result

      open(OUTPUT, “snmpwalk -v1 -c ${communitystring} ${stack} IF-MIB::ifName.${port_id}|”);
      @OUTPUT = <OUTPUT>;
      close(OUTPUT);

      $switch_port=”@OUTPUT”;
      chomp $switch_port;
      $switch = ((split /Slot: /, ${switch_port})[1]);
      $switch = ((split / Port:/, ${switch})[0]);

 

Perl Loops 150 150 Roderick Derks

Perl Loops

Perl supports four main loop types:

  1. while

  2. for

  3. until

  4. foreach

In each case, the execution of the loop continues until the evaluation of the supplied expression changes.

  • In the case of a while loop execution continues while the expression evaluates to true.
  • The until loop executes while the loop expression is false and only stops when the expression evaluates to a true value.
  • The list forms of the for and foreach loop are special cases. They continue until the end of the supplied list is reached.

while Loops

The while loop has three forms:

while EXPRLABEL
while (EXPR) BLOCKLABEL
while (EXPR) BLOCK continue BLOCK

In first form, the expression is evaluated first, and then the statement to which it applies is evaluated. For example, the following line increases the value of $linecount as long as we continue to read lines from a given file:

For example, the following line increases the value of $linecount as long as we continue to read lines from a given file:

$linecount++ while ();

To create a loop that executes statements first, and then tests an expression, you need to combine while with a preceding do {} statement. For example:

do
{
$calc += ($fact*$ivalue);
} while $calc <100;

In this case, the code block is executed first, and the conditional expression is only evaluated at the end of each loop iteration.

The second two forms of the while loop repeatedly execute the code block as long as the result from the conditional expression is true. For example, you could rewrite the preceding example as:

while($calc < 100)
{
$calc += ($fact*$ivalue);
}

The continue block is executed immediately after the main block and is primarily used as a method for executing a given statement (or statements) for each iteration, irrespective of how the current iteration terminated. It is somehow equivalent to for loop

{
my $i = 0;
while ($i <100)
{ ... }
continue
{
$i++;
}
}

This is equivalent to
for (my $i = 0; $i < 100; $i++)
{ ... }

for Loops

A for loop is basically a while loop with an additional expression used to reevaluate the original conditional expression. The basic format is:

LABEL for (EXPR; EXPR; EXPR) BLOCK

The first EXPR is the initialization – the value of the variables before the loop starts iterating. The second is the expression to be executed for each iteration of the loop as a test. The third expression is executed for each iteration and should be a modifier for the loop variables.

Thus, you can write a loop to iterate 100 times like this:

for ($i=0;$i<100;$i++)
{
...
}

You can place multiple variables into the expressions using the standard list operator (the comma):

for ($i=0, $j=0;$i<100;$i++,$j++)

You can create an infinite loop like this:

for(;;)
{
...
}

until Loops

The inverse of the while loop is the until loop, which evaluates the conditional expression and reiterates over the loop only when the expression returns false. Once the expression returns true, the loop ends.

In the case of a do.until loop, the conditional expression is only evaluated at the end of the code block. In an until (EXPR) BLOCK loop, the expression is evaluated before the block executes. Using an until loop, you could rewrite the previous example as:

do
{
$calc += ($fact*$ivalue);
} until $calc >= 100;

This is equivalent to

do
{
$calc += ($fact*$ivalue);
} while $calc <100;

foreach Loops

The last loop type is the foreach loop, which has a format like this:

LABEL foreach VAR (LIST) BLOCK
LABEL foreach VAR (LIST) BLOCK continue BLOCK

Using a for loop, you can iterate through the list using:

for ($index=0;$index<=@months;$index++)
{
print "$months[$index]\n";
}

This is messy, because you.re manually selecting the individual elements from the array and using an additional variable, $index, to extract the information. Using a foreach loop, you can simplify the process:

foreach (@months)
{
print "$_\n";
}

The foreach loop can even be used to iterate through a hash, providing you return the list of values or keys from the hash as the list:

foreach $key (keys %monthstonum)
{
print "Month $monthstonum{$key} is $key\n";
}

Labled Loops

Labels can be applied to any block, but they make the most sense on loops. By giving your loop a name, you allow the loop control keywords to specify which loop their operation should be applied to. The format for a labeled loop is:

LABEL: loop (EXPR) BLOCK ...

For example, to label a for loop:

ITERATE: for (my $i=1; $i<100; $i++)
{
print "Count: $i\n";
}

Loop Control – next, last and redo

There are three loop control keywords: next, last, and redo.

The next keyword skips the remainder of the code block, forcing the loop to proceed to the next value in the loop. For example:

while (<DATA>)
{
next if /^#/;
}

Above code would skip lines from the file if they started with a hash symbol. If there is a continue block, it is executed before execution proceeds to the next iteration of the loop.

The last keyword ends the loop entirely, skipping the remaining statements in the code block, as well as dropping out of the loop. The last keyword is therefore identical to the break keyword in C and Shellscript. For example:

while ()
{
last if ($found);
}

Would exit the loop if the value of $found was true, whether the end of the file had actually been reached or not. The continue block is not executed.

The redo keyword reexecutes the code block without reevaluating the conditional statement for the loop. This skips the remainder of the code block and also the continue block before the main code block is reexecuted. For example, the following code would read the next line from a file if the current line terminates with a backslash:

while(<DATA>)
{
if (s#\\$#)
{
$_ .= <DATA>;
redo;
}
}

Here is an example showing how labels are used in inner and outer loops

OUTER:
while(<DATA>)
{
chomp;
@linearray=split;
foreach $word (@linearray)
{
next OUTER if ($word =~ /next/i)
}
}

goto Statement

There are three basic forms: goto LABEL, goto EXPR, and goto &NAME. In each case, execution is moved from the current location to the destination.

In the case of goto LABEL, execution stops at the current point and resumes at the point of the label specified.

The goto &NAME statement is more complex. It allows you to replace the currently executing subroutine with a call to the specified subroutine instead.

Centreon and Nagios 491 250 Roderick Derks

Centreon and Nagios

Since a year I've been working with Nagios, an open source system and network monitoring tool. In the company I work for I check around 300 hosts and almost a thousand services, mostly by using SNMP plugins. Some of them are the standard plugins that come with Nagios and sometimes needed a little tweak to get the right output, others I created myself. With Nagios it's fairly easy to configure sending alerts via email and sms. Some hosts send them during office hours, and others 24 hours a day. This all was a big step forward in actively monitoring our network.

Then I started to use Nagiosgrapher to make some nice graphs of the output of the plugins. For example: diskusage, cpu usage, memory usage, temperatures, nr of processes, load averages, etc. Really cool for detecting trends and this enhanced our ability of pro-actively monitoring servers and network components.

Nagios was accepted and adopted by my collegues (and they are not easy to convince). This was good news, but at the same time I realised I also created a problem. I was about the only one at the office who understood the configuration Nagios: all changes had to go through me and during my long vacations no changes were being made. You have to understand the structure of the files and the directories, and also the dependencies of host, services, serviceextensions, commands, etc to be able to add a server or a service. A little guide for Nagios Dummies did not help. And then offcourse people have to know how to work with Linux and an editor like vi (even if it's weird that there are still professional ict guys who never worked with Linux).

So I was looking for a way to be able to configure Nagios through a webinterface. A few weeks ago I heard about the Centreon project. Centreon is a tool that configures and controls Nagios via the webinterface and stores the output of the Nagios plugins into a MySQL database. This data is used to show the status of the hosts and services like nagios does. And Centreon creates graphs from this data. This all sounded very promissing so I decided to give it a try.

It took me about two weeks to get Centreon running on my Nagios server and I have to say that it was worth the effort. A bit of a problem is the lack of documentation and some of it is in French. So you have to work with it for a while to get the hang of it and to understand what is happening. But don't be afraid, the forum is lively and it turned out to be a great help.

The result is worthwile. After I imported my current Nagios configuration (not well documented on the centreon wiki) I found out that Centreon makes it easier to configure Nagios. You still have to understand a bit how Nagios works, this does not change offcourse, but it's pretty easy do changes or add and delete a server or a service. Centreon uses a database to store the collected data from the plugins and this gives us a lot of options what to do with it.

The website gives us a much more professional look and feel compared to the Nagios site. The graphs are beautiful and the way they are presented in the webinterface is really cool. Centreon is able to produce different graphs of the same or even of different hosts on the same webpage. I have to add the fact that I had to change the output of some of the plugins that I used to create the graphs so this took a while to get things running. But I'm happy with it because it improved the quality of the plugins. By the way, Centreon comes with it's own set of plugins and some of them are very good, like the plugin to get CPU usage of Windows and Linux hosts.

The reporting tool shows the availability of hosts and services and looks good, especially when you take a look at the timeline of the status of a host or a service. Because of the use of AJAX you can scroll back and forth on the timeline. And to my surprise all of the Nagios history was imported into Centreon by itself. So I can scroll back a year even if I just installed Centreon. Really great!

So, I'm using Nagios 3.0.3 and Centreon RC2 with NDO-utis (cvs version). I ran into some Centreon bugs like that some buttons are not exactly doing what they are supposed to do, but this is not a problem. Guess these bugs will be fixed before the stable version is released. You got to use cvs version of NDO tools to get the data from Nagios to the NDO database, the stable version did not work.

Alright, that's it. Hope this article helps you out a bit.

La Marmotte 2008 150 150 Roderick Derks

La Marmotte 2008

Vanochtend werd ik om 04:45 uur wakker, dezelfde tijd dat ik op had willen staan. Daarna werd ik weer wakker om 07:00 uur, de starttijd van de Marmotte. Ik zag al die duizenden fietsers voor me en het leek bijna alsof ik er ook tussenstond. Maar ipv dat ik op de fiets stapte om naar de Glandon te rijden ben ik opgestaan om wat paracetamol te nemen om daarna nog eventjes als een marmot te gaan slapen. Om 15:00 uur werd ik weer onrustig omdat dat ongeveer het moment was waarop ik zou gaan finishen. Nou, dat was het dus wel zo’n beetje.

read more

Vaujany 2008 150 150 Roderick Derks

Vaujany 2008

Zondag 29 juni om 7:15 gestart en de eerste 23 km net als vorig jaar rijden we stroomafwaarts langs de l’Oisan. Het gaat net als vorig jaar erg hard en 1e groep waarin ik rij is groot. Op een gegeven moment moeten we langs een tegemoetkomende bus en dat zorgt ervoor dat het peleton moet knijpen en zo ontstaat er een valpartij. Gelukkig rijden we niet hard op dat moment maar helaas lig ik ook op de grond. Tijdens de val merk ik nog hoe licht mijn fiets is, en dat het grappig is dat dit ook op een moment als dit merkbaar is.

read more

Col de Joux Plane, 4 km voor de finish
Morzine Vallée d’Aulps 2008 133 200 Roderick Derks

Morzine Vallée d’Aulps 2008

De middag na de laatste rit van de Ardechoise staat een verplaatsing op het programma van St. Félicien naar Morzine in de Haute Savoie, niet ver van Genève. Na een rit van 5 uur en terwijl ik onderweg in Genève een hele grote luchtballon in de vorm en de kleuren van een voetbal zie, kom ik aan in Morzine en ben ik nog net op tijd om me in te schrijven voor de wedstrijd.

read more

    Your Name (required)

    Your Email (required)

    Subject

    Your Message

      Your Name (required)

      Your Email (required)

      Subject

      Your Message