home *** CD-ROM | disk | FTP | other *** search
/ developer.apple.com / developer.apple.com.tar / developer.apple.com / appleapplications / SystemReport.dmg / main.command < prev    next >
Text File  |  2007-04-16  |  3KB  |  67 lines

  1. #!/bin/bash
  2.  
  3. #
  4. # systemreport.sh
  5. #
  6. # systemreport runs the system_profiler utility on each remote machine.
  7. # It then transforms the system_profiler data into an HTML report using XSLT.
  8. #
  9. # The list of remote machines is provided, one per line, on stdin.
  10. # Each remote machine is specified using the [user@]address format used by ssh.
  11. # ssh cannot prompt for passwords, so each remote machine must be configured for
  12. #    password-less ssh access (see man ssh, authorized_keys).
  13. #
  14.  
  15. # The script's support files are expected to be in the same directory
  16. cd "$(dirname "${0}")"
  17.  
  18. # Custom Shell Script Action parameters are passed as environment variables.
  19. # If the parameter is not choosen or empty, the variable is missing.
  20. # Establish empty values for parameters that are omitted.
  21. if [[ ! "${reportTitle}" ]]; then reportTitle='System Inventory Report'; fi
  22. if [[ ! "${showSpeed}" ]]; then showSpeed=0; fi
  23. if [[ ! "${showKernel}" ]]; then showKernel=0; fi
  24. if [[ ! "${showSerialNumber}" ]]; then showSerialNumber=0; fi
  25.  
  26. # HTML prolog (be careful with syntax; this text is preprocessed by the shell)
  27. cat << _HEAD
  28. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  29. <html xmlns="http://www.w3.org/1999/xhtml"><head><title>Macintosh System Inventory</title><style type="text/css">
  30. /*<![CDATA[*/
  31. body { text-align: left; font-family: "Lucida Grande", Lucida, Verdana, sans-serif; }
  32. h1 { font-size: 16px; text-align: center; }
  33. h2 { font-size: 13px; text-align: center; }
  34. table { width: 94%; font-size: 10px; background-color: #eee; margin-left: 12px; border-style: dotted; border-width: 1px; }
  35. table td { padding: 4px; border-top: 1px dotted #777; }
  36. table tr:first-child { font-size: 12px; font-weight: bold; font-style: italic; background-color: #fee; }
  37. table tr:first-child td { border: none; }
  38. /*]]>*/</style></head><body><h1>${reportTitle}</h1><h2>Generated $(date '+%v %R')</h2>
  39. <table>
  40. _HEAD
  41.  
  42. # reportheaders.xml contains a property list that produces the column headers
  43. xsltproc --stringparam ShowSpeed ${showSpeed} \
  44.          --stringparam ShowKernel ${showKernel} \
  45.          --stringparam ShowSerialNumber ${showSerialNumber} \
  46.          sysinfo2inventory.xsl reportheaders.xml
  47.  
  48. # Add a report record for each machine read from stdin
  49. while read m
  50. do
  51.     # Execute system_profiler on the remote computer and capture the results.
  52.     # Pipe the XML from system_profiler through an XML transform to produce an HTML table row
  53.     # Action choices appear as environment variables; pass to the XSL as parameters
  54.     ssh -n ${m} system_profiler -xml SPHardwareDataType SPSoftwareDataType |
  55.         xsltproc flattenplist.xsl - |
  56.         xsltproc --stringparam NetworkAddress ${m} \
  57.                  --stringparam ShowSpeed ${showSpeed} \
  58.                  --stringparam ShowKernel ${showKernel} \
  59.                  --stringparam ShowSerialNumber ${showSerialNumber} \
  60.                  sysinfo2inventory.xsl -
  61. done
  62.  
  63. # HTML epilog
  64. cat << _END
  65. </table></body></html>
  66. _END
  67.