Home » Infrastructure » Unix » Can I make a script to check peripheral serials against a DB?
Can I make a script to check peripheral serials against a DB? [message #168046] Tue, 18 April 2006 09:35 Go to next message
Azrael
Messages: 8
Registered: April 2006
Junior Member
I am working on a basic unix asset management database, and wish to remove some of the human element by having a script, run periodically via crontab, to check the serial numbers of peripherals (listed as part of iostat -En I believe) attatched to a unix machine against those on a database. Where it finds a device in the database that has the same serial number, the entry will be marked as updated by having a 'last updated' field marked with the current date, and the field listing the machine it is attatched to is set to match the machine running the script. The idea is that the script will detect movement of kit from one machine to another.

I'm thinking of using C, but Im open to suggestions. I dont think it should be too complicated, I just want to gather ideas. Here's the flow just to summerise:

List serial numbers of attatched devices (iostat -En)
Check against database table of devices
For each device with a matching serial number, set host to this machine, set 'last updated' to today's date
Re: Can I make a script to check peripheral serials against a DB? [message #168511 is a reply to message #168046] Thu, 20 April 2006 16:40 Go to previous messageGo to next message
Azrael
Messages: 8
Registered: April 2006
Junior Member
Done some thinking and I think unix shell script is probably best, can anyone give some pointers?
Re: Can I make a script to check peripheral serials against a DB? [message #168655 is a reply to message #168511] Fri, 21 April 2006 08:22 Go to previous messageGo to next message
Mahesh Rajendran
Messages: 10708
Registered: March 2002
Location: oracleDocoVille
Senior Member
Account Moderator
>> List serial numbers of attatched devices (iostat -En)
A simple awk can do this.
>> Check against database table of devices
What kind of database?
Re: Can I make a script to check peripheral serials against a DB? [message #168732 is a reply to message #168655] Fri, 21 April 2006 18:52 Go to previous messageGo to next message
Azrael
Messages: 8
Registered: April 2006
Junior Member
I'm afraid I dont understand your question. Its an oracle 10g database of hardware. The table in question records peripherals (I/O devices) with details like manufacturer, model, asset number, serial number. Is that what you mean?

What is a good resource for awk? What advantage does it have over shell scripting?

[Updated on: Fri, 21 April 2006 18:59]

Report message to a moderator

Re: Can I make a script to check peripheral serials against a DB? [message #168819 is a reply to message #168732] Sun, 23 April 2006 07:18 Go to previous messageGo to next message
Mahesh Rajendran
Messages: 10708
Registered: March 2002
Location: oracleDocoVille
Senior Member
Account Moderator
This is not a complete solution. (Sorry i am running out of time to give you a complete working solution).

I have written a simple script that will
issue iostat command,picksout only the serial number ( This works inn solaris. play with awk for other *nix) and will process line-by-line.Each serial number is checked against the database.
Keeping this as a base model,
You need to
change the sql embedded inside so that, an update is issued if the serial_no does not exist and do all your related business.
if you are looking into scanning a huge list of devices, you want to do an array processing ( instead of doing one-by-one).

oracle@hemlock#cat somescript
#!/usr/bin/bash
iostat -En | grep Vendor | awk '{print $9}' | while read sr
do
echo $sr
sqlplus -s scott/tiger <<EOF
set linesize 100
column product format a15
column vendor format a15
column serial_no format a20

select * from device where serial_no='$sr';
exit;
EOF
done


oracle@hemlock#./somescript
3JKPW71W00007242

VENDOR          PRODUCT         SERIAL_NO            LAST_UDAT HOST
--------------- --------------- -------------------- --------- ------------------------------
SEAGATE         ST318305LSUN18G 3JKPW71W00007242

3JKPYE2200002245

VENDOR          PRODUCT         SERIAL_NO            LAST_UDAT HOST
--------------- --------------- -------------------- --------- ------------------------------
SEAGATE         ST318305LSUN18G 3JKPYE2200002245



no rows selected

oracle@hemlock#

>>What is a good resource for awk?
Google?
Just google for awk tutorial.
>> What advantage does it have over shell scripting?
Both are supposed to be used together.
AWK is like sql ( to query a text file).
Re: Can I make a script to check peripheral serials against a DB? [message #168964 is a reply to message #168819] Mon, 24 April 2006 07:25 Go to previous message
Azrael
Messages: 8
Registered: April 2006
Junior Member
Much appreciated! Very helpful indeed, I shall play with that a bit.
Previous Topic: Error in loading Oracle 9i (Rel-2) on Tru64
Next Topic: listing only directories
Goto Forum:
  


Current Time: Mon Nov 25 18:15:29 CST 2024