Unix: Automating your server inventory

By  

On this particular system, one of the four CPUs is running at a different speed than the other three.

$ ./getSysInfo
Name: vader.aacc.edu
IP: 192.168.0.6
CPUs: 2
Cores: 4
Processor speed (MHz):       1 2800.000
      3 3400.000
Disk(s): OS: 2.6.18-371.3.1.el5 GNU/Linux
  Red Hat Enterprise Linux Server release 5.10 (Tikanga)
Memory: 2074932 kB
Up for: 115 days, 4:28,
Manufacturer: HP
Model: ProLiant DL380 G4

To add some Oracle-specific queries, I put the queries that I wanted to run into a .sql file and then called the sql file from within my bash script. The sql file that I used looks like this and is called getVersionInstall.sql:

connect / as sysdba;
select * from v$version;
select ora_database_name from dual;
select created, sysdate from v$database;
exit

This sql script gathers some information such as the Oracle release, the database name, and the date that the database was first set up. The output of these commands is a bit verbose (see below), so we'll store it in a file and then select only what we want to see in our script output.

SQL*Plus: Release 11.2.0.2.0 Production on Wed May 7 10:30:37 2014

Copyright (c) 1982, 2010, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Release 11.2.0.2.0 - 64bit Production
With the Automatic Storage Management option

Connected.

BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Release 11.2.0.2.0 - 64bit Production
PL/SQL Release 11.2.0.2.0 - Production
CORE    11.2.0.2.0      Production
TNS for Linux: Version 11.2.0.2.0 - Production
NLSRTL Version 11.2.0.2.0 - Production


ORA_DATABASE_NAME
--------------------------------------------------------------------------------
DEVDB


CREATED   SYSDATE
--------- ---------
11-SEP-11 12-MAY-14

Disconnected from Oracle Database 11g Release 11.2.0.2.0 - 64bit Production
With the Automatic Storage Management option

To incorporate the database information collection into the script, I added these lines:

echo
echo -n "Service Name: "
for file in `find $ORACLE_HOME -name tnsnames.ora -print`
do
    grep SERVICE_NAME $file | awk '{print $NF}' | sed "s/)//"
done

su -c "sqlplus '/as sysdba' @getVersionInstall.sql" oracle > ostats

echo
grep -A 2 BANNER ostats
echo
grep -A 2 DATABASE ostats
echo
grep -A 2 CREATED ostats

Notice that we're getting the service name from the tnsnames.ora file and running the sqlplus command as the oracle user to get the additional information. It sends its output to a ostats file and the script then reads in portions of this file using grep -A commands to retrieve the information we are looking for.

Join us:
Facebook

Twitter

Pinterest

Tumblr

LinkedIn

Google+

Answers - Powered by ITworld

ITworld Answers helps you solve problems and share expertise. Ask a question or take a crack at answering the new questions below.

Ask a Question
randomness