PDA

View Full Version : SQL Question




bigMAC28
Aug 2, 2013, 01:35 PM
Hi guys,

Is it possible to write a script that pulls basic computer info (Name,PC Model Number, Processor speed) that will run when a machine is imaged using pxe boot, then update the database using said information?



robvas
Aug 2, 2013, 02:29 PM
Just split it into a few parts:


$ sysctl machdep.cpu.brand_string
machdep.cpu.brand_string: Intel(R) Core(TM) i5-2467M CPU @ 1.60GHz

$ echo $HOSTNAME
Bill-iMac.local

$ sysctl hw.model
hw.model: MacBookAir4,1


I'll leave it up to you to decide how you want to put that into a SQL database. Store them as variables in a bash script and then just upload them with an INSERT statement, running from a MySQL command prompt.

mysql -e "use database_name; insert into table_name values (...);"

mrichmon
Aug 2, 2013, 11:56 PM
Another source for the data is:

$ system_profiler SPHardwareDataType SPSoftwareDataType

It is possible to write code to do this when a machine PXE boots. You'll need to work out where to host the database. This is probably easiest to achieve by creating a custom Linux boot image and then deploy that image on a PXE server. But this is quite a bit more work than just writing a script.