I'm working on a bash script to pull serial numbers and part numbers from all the devices in a server rack, my goal is to be able to run a single script (inventory.sh) and walk away while it generates text files containing the information I need. I'm using bash for maximum compatibility, the RHEL 6.7 systems do have Perl and Python installed, however they have minimal libraries. So far I haven't had to use anything other than bash, but I'm not against calling a Perl or Python script from my bash script.
I need to retrieve the Serial Numbers and Part numbers from the drives in a Dot Hill Systems AssuredSAN 3824, as well as the Serial numbers from the equipment inside. The only way I have found to get all the information I need is to connect over SSH and run the following three commands dumping the output to a local file:
I ended up contacting the Manufacturer and asking my question. They said that the system isn't setup for connecting without a password, and their SNMP is very basic and won't provide the information I need. They said to connect to the system with FTP and use "get logs " to download an archive of the configuration and logs. Not exactly ideal as it takes 4 minutes just to run that one command but it seems to be my only option. Below is the script I wrote to retrieve the file automatically by adding the login credentials to the .netrc file. This works on RHEL 6.7:
#!/bin/bash #Retrieve the logs and configuration from a Dot Hill Systems AssuredSAN 3824 automatically. #Modify "LINE" and "HOST" to fit your configuration. LINE='machine <IP> login manage password <password>' HOST='<IP>' AUTOLOGIN="/root/.netrc" FILE='logfiles.zip' #Check for and verify the autologin file if [ -f $AUTOLOGIN ]; then printf "Found auto-login file, checking for proper entry... \r" READLINE=`cat $AUTOLOGIN | grep "$LINE"` #Append the line to the end of .netrc if file exists but not the line. if [ "$LINE" != "$READLINE" ]; then printf "Proper entry not found, creating it... \r" echo "$LINE" >> "$AUTOLOGIN" else printf "Proper entry found... \r" fi #Create the Autologin file if it doesn't exist else printf "Auto-Login file does not exist, creating it and setting permissions...\r" echo "$LINE" > "$AUTOLOGIN" chmod 600 "$AUTOLOGIN" fi #Start getting the information from the controller. (This takes a VERY long time) printf "Retrieving Storage Controller data, this will take awhile... \r" ftp $HOST << SCRIPT get logs $FILE SCRIPT exit 0
This gave me a bunch of files in the zip, but all I needed was the "store_....logs" file. It was about 500,000 lines long, the first portion is the entire configuration in XML format, then the configuration in text format, followed by the logs from the system. I parsed the file and stripped off the logs at the end which cut the file down to 15,000 lines. From there I divided it into two files (config.xml and config.txt). I then pulled the XML output of the 3 commands that I needed and it to the 3 files my previously written script searches for. Now my inventory script pulls in everything it needs, albeit pretty slow due to waiting 4 minutes for the system to generate the zip file. I hope this helps someone in the future.