0

I have a peculiar situation lets do a background.

Background:

We have a script that was developed in house for testing enterprise servers. The script is written in Bash. The magic of the script is the dmidecode command. The script runs on Linux Mint and is deployed via PXE. The output of the script contains hardware information about the processor, memory, system board and chassis part numbers, etc. This information is always changing depending on the device the image is booted on. All this data is then grepped into a readable format that then manually gets added into an Excel spreadsheet. The Excel sheet is broken up like this Row 1: A1(Asset Number),B1(Qty."always 1"),C1(Manufacturer),D1(Model),E1(Part Number),F1(Serial Number), G1(RAM (Mb)),H1(# of CPUs),L1(CPU Speed(GHZ))

Example Data Column Names:

Column Data: Row 2: 6112, 1, HP, Proliant DL580 G2, 325134-001, USE247ML97, 1024, 2, 2.8

So each row represents an individual server, the columns contain the data that comes from our previously mentioned bash script.

Goal:

OK, so my goal is to have the output of the bash script automatically be appended to an existing Worksheet that is stored on a local CIFS File Server. Since script is initiated on Linux, Powershell is not a viable option. I think Openpyxl can do the job but I have no idea the best practice to approach this. I know that I will not be able to modify an existing workbook. Given that, I was thinking about loading an existing document in memory and overwriting with the same file name. Also, all the tutorials I see for Openpyxl seem to have static data, I do not have this luxury. Is this even possible or just a subtle daydream?

2
  • Consider replacing the 2 tags append & scripting with python and perl as both of these can write Excel files. Try and write 3 lines of Python openpyxl to append a couple of static rows to a simple workbook, then all you need to learn is how to read the output of your dmidecode into Python variables. Commented Jul 24, 2017 at 21:13
  • Thanks for the advice,I changed the tags. Commented Jul 25, 2017 at 12:04

1 Answer 1

1

For an excel sheet i would use XLSX parser to read the spreadsheet and XLSX writer to make a whole new spreadsheet based on what you have read. However, for what you appear to be doing. Would it not be easier to put STDIO into a CSV?

e.g,

echo $VAR , $VARB , $VARC >> ~/servers.csv
Sign up to request clarification or add additional context in comments.

1 Comment

Great idea! Im going to rewrite the old script to have vars that spit out the data that I actually need. Ill post the results!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.