From Technical Knowledge to IT Service Management

Archive for the ‘Shell’ Category

Non alphanumeric files

If you want to list all the non alphanumeric files:

ls -R | grep -iv ^[a-z0-9\._-]*$

Générer un rapport AWR

J’ai recu une demande pour savoir comment générer un rapport AWR sous Oracle.

Voici un petit exemple pour se connecter à la base et générer un AWR en mode test


[root@nuxora01 ~]# su - oracle
[oracle@nuxora01 ~]$ export ORACLE_SID=nuxodb
[oracle@nuxora01 ~]$ sqlplus system@nuxodb
SQL*Plus: Release 10.2.0.1.0 - Production on Sun Aug 31 08:40:22 2008
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
Enter password:
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning and Data Mining options
SQL> @$ORACLE_HOME/rdbms/admin/awrrpt.sql
Current Instance
~~~~~~~~~~~~~~~~
   DB Id    DB Name      Inst Num Instance
----------- ------------ -------- ------------
  731622690 NUXODB              1 nuxodb

Specify the Report Type
~~~~~~~~~~~~~~~~~~~~~~~
Would you like an HTML report, or a plain text report?
Enter 'html' for an HTML report, or 'text' for plain text
Defaults to 'html'
Enter value for report_type: text
Type Specified:  text

Instances in this Workload Repository schema
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   DB Id     Inst Num DB Name      Instance     Host
------------ -------- ------------ ------------ ------------
* 731622690         1 NUXODB       nuxodb       nuxora01
Using  731622690 for database Id
Using          1 for instance number

Specify the number of days of snapshots to choose from
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Entering the number of days (n) will result in the most recent
(n) days of snapshots being listed.  Pressing <return> without
specifying a number lists all completed snapshots.

Enter value for num_days: 1
Listing the last day's Completed Snapshots
                                                        Snap
Instance     DB Name        Snap Id    Snap Started    Level
------------ ------------ --------- ------------------ -----
nuxodb       NUXODB            1510 29 Aug 2008 06:26      1
                               1511 29 Aug 2008 06:45      1
                               1512 29 Aug 2008 07:00      1
                               1513 29 Aug 2008 07:15      1
                               1514 29 Aug 2008 07:30      1
                               1515 29 Aug 2008 07:45      1

Specify the Begin and End Snapshot Ids
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Enter value for begin_snap: 1514
Begin Snapshot Id specified: 1514
Enter value for end_snap: 1515
End   Snapshot Id specified: 1515

Specify the Report Name
~~~~~~~~~~~~~~~~~~~~~~~
The default report file name is awrrpt_1_1514_1515.txt.  To use this name,
press <return> to continue, otherwise enter an alternative.
Enter value for report_name:
Using the report name awrrpt_1_1514_1515.txt
WORKLOAD REPOSITORY report for
DB Name         DB Id    Instance     Inst Num Release     RAC Host
------------ ----------- ------------ -------- ----------- --- ------------
NUXODB         731622690 nuxodb              1 10.2.0.1.0  NO  nuxora01
              Snap Id      Snap Time      Sessions Curs/Sess
            --------- ------------------- -------- ---------
Begin Snap:      1514 29-Aug-08 07:30:23        18       2.1
  End Snap:      1515 29-Aug-08 07:45:24        18       2.1
   Elapsed:               15.01 (mins)
   DB Time:                0.01 (mins)
Cache Sizes
~~~~~~~~~~~                       Begin        End
                             ---------- ----------
               Buffer Cache:       180M       180M  Std Block Size:         8K
           Shared Pool Size:        76M        76M      Log Buffer:     7,000K
Load Profile
~~~~~~~~~~~~                            Per Second       Per Transaction
                                   ---------------       ---------------
                  Redo size:                694.24              7,269.72
              Logical reads:                 27.06                283.31
              Block changes:                  2.05                 21.42
             Physical reads:                  0.07                  0.78
            Physical writes:                  0.48                  5.06
                 User calls:                  0.10                  1.05
                     Parses:                  1.88                 19.67
                Hard parses:                  0.35                  3.64
                      Sorts:                  1.50                 15.74
                     Logons:                  0.03                  0.35
                   Executes:                  4.53                 47.49
               Transactions:                  0.10
  % Blocks changed per Read:    7.56    Recursive Call %:    99.79
 Rollback per transaction %:    0.00       Rows per Sort:     7.74
Instance Efficiency Percentages (Target 100%)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            Buffer Nowait %:  100.00       Redo NoWait %:  100.00
            Buffer  Hit   %:   99.73    In-memory Sort %:  100.00
            Library Hit   %:   83.14        Soft Parse %:   81.50
         Execute to Parse %:   58.57         Latch Hit %:  100.00
Parse CPU to Parse Elapsd %:   83.33     % Non-Parse CPU:   35.22
 Shared Pool Statistics        Begin    End
                              ------  ------
             Memory Usage %:   82.16   82.43
    % SQL with executions>1:   63.84   78.55
  % Memory for SQL w/exec>1:   84.04   90.26
Top 5 Timed Events                                         Avg %Total
~~~~~~~~~~~~~~~~~~                                        wait   Call
Event                                 Waits    Time (s)   (ms)   Time Wait Class
------------------------------ ------------ ----------- ------ ------ ----------
CPU time                                              1          92.7
os thread startup                        16           1     42   90.3 Concurrenc
control file parallel write             299           1      2   90.1 System I/O
log file parallel write                 111           0      2   27.2 System I/O
db file sequential read                  17           0      3    7.5   User I/O
          -------------------------------------------------------------
......
          -------------------------------------------------------------
End of Report
Report written to awrrpt_1_1514_1515.txt
SQL> quit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning and Data Mining options
[oracle@nuxora01 ~]$ ll
total 100
-rw-r--r--  1 oracle dba 95022 Aug 31 08:40 awrrpt_1_1514_1515.txt
[oracle@nuxora01 ~]$

				

Nagios – demarrage & arret

>>> I. Test et verification

Nagios adopte une configuration modulaire, il n’est pas rare d’oublier le definition d’un contact, oublier une parenthese,….
Pour tester votre configuration actuelle de Nagios executer /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

Voici le resultat:

$/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

Nagios 2.9
Copyright (c) 1999-2007 Ethan Galstad (http://www.nagios.org)
Last Modified: 04-10-2007
License: GPL

Reading configuration data…

Running pre-flight check on configuration data…

Checking services…
Warning: Service ‘Load’ on host ‘Serveur_01′  has no default contact group(s) defined!
Checked 155 services.
Checking hosts…
Warning: Host ‘Serveur_02′ has no services associated with it!
Checked 94 hosts.
Checking host groups…
Checked 14 host groups.
Checking service groups…
Checked 1 service groups.
Checking contacts…
Checked 3 contacts.
Checking contact groups…
Checked 2 contact groups.
Checking service escalations…
Checked 0 service escalations.
Checking service dependencies…
Checked 0 service dependencies.
Checking host escalations…
Checked 0 host escalations.
Checking host dependencies…
Checked 0 host dependencies.
Checking commands…
Checked 30 commands.
Checking time periods…
Checked 5 time periods.
Checking extended host info definitions…
Checked 0 extended host info definitions.
Checking extended service info definitions…
Checked 0 extended service info definitions.
Checking for circular paths between hosts…
Checking for circular host and service dependencies…
Checking global event handlers…
Checking obsessive compulsive processor commands…
Checking misc settings…

Total Warnings: 2
Total Errors:   0

Things look okay – No serious problems were detected during the pre-flight check

J’ai volontairement laissé de “petites” erreurs dans la configuration, ces dernieres sont sans conséquences pour le bon fonctionnement de Nagios, il s’agit de Warning. Nagios pourra etre lancé.

Si nous avions eu une erreur, par exemple

$/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

Nagios 2.9
Copyright (c) 1999-2007 Ethan Galstad (http://www.nagios.org)
Last Modified: 04-10-2007
License: GPL

Reading configuration data…

Error: Could not find any host matching ‘Serveur_99′
Error: Could not expand hostgroups and/or hosts specified in service (config file ‘/usr/local/nagios/etc/services.cfg’, starting on line 12)

***> One or more problems was encountered while processing the config files…

Check your configuration file(s) to ensure that they contain valid
directives and data defintions.  If you are upgrading from a previous
version of Nagios, you should be aware that some variables/definitions
may have been removed or modified in this version.  Make sure to read
the HTML documentation regarding the config files, as well as the
‘Whats New’ section to find out what has changed.

J’ai volontairement defini un service avec un serveur qui n’etait pas defini, ce qui explique l’erreur ci dessus.
Il faut donc corriger toutes les erreurs, nous pourrons ensuite demarrer nagios

>>> II. Lancement

# Lacement classique (foreground process)
$ /usr/local/nagios/bin/nagios /usr/local/nagios/etc/nagios.cfg
> pour l’arret un CTRL+C suffit

To stop Nagios at any time, just press CTRL-C. If you’ve enabled the debugging options you’ll probably want to redirect the output to a file for easier review later.

# Lancement silencieux (Background Process)
$ /usr/local/nagios/bin/nagios /usr/local/nagios/etc/nagios.cfg &

# Lancement en tant que Daemon
$ /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg

Ces differentes methodes sont utiles sur des plateformes de test ou sur un pc pour tester le produit, en fonctionnement de production, il faudra adapter le choix suivant.

# Start Nagios
$ /etc/rc.d/init.d/nagios start

# Stop Nagios (tue le process lancé par nagios start)
$ /etc/rc.d/init.d/nagios stop

# Restart Nagios (=nagios stop puis nagios start)
$ /etc/rc.d/init.d/nagios restart

# Reload Configuration Data (envois un SIGHUP au process Nagios, forcant une prise en compte immédiate des nouveaux fichiers de configuration, l’avantage est de ne pas couper le process, par exemple an cas d’ajout d’un serveur ou d’un service)
$ /etc/rc.d/init.d/nagios reload

Log SQL results

If you’d like to log the result from a sql script, just prepare your sql script like that:spool result.log
SET SERVEROUTPUT ON
select * from dual;
spool off
exit

Then from a command line or a script shell execute the following command:
# sqlplus user/pwd@db_name @script.sql