Open main menu

CDOT Wiki β

Lab1 Shell Script Demo

Revision as of 21:58, 16 January 2015 by Msaul (talk | contribs) (Created page with '#!/bin/bash # report.bash # # Author: Murray Saul # Date: January 16, 2015 # # Purpose: To present sysadmin to create an software inventory # report containing selected…')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
  1. !/bin/bash
  1. report.bash
  2. Author: Murray Saul
  3. Date: January 16, 2015
  4. Purpose: To present sysadmin to create an software inventory
  5. report containing selected elements
  1. Check to see if logged in as root to be able to create file
  2. in /root/ directory...

if [ $USER != "root" ] then

  echo "You must be logged in as root to run the command."
  echo "Either login as root or issue command \"sudo ./report1.bash\""
  exit 1

fi


  1. Create report title

echo "SOFTWARE ASSET REPORT FOR INSTALLED LINUX SYSTEM" > /root/report.txt echo "Date: $(date +'%A %B %d, %Y (%H:%M:%p)')" >> /root/report.txt echo >> /root/report.txt

  1. Using zenity (dialog box constructor)
  2. Prompts user for elements to be included in the report...
  3. Activated check box returns values (multiple values | symbol )...

items=$(zenity --height 320 --width 290 --text "Please select elements\nthat you want to display in report:\n" --list --checklist --column "Session Type" --column "Description" TRUE "Kernel" TRUE "Processes" TRUE "Hostname" FALSE "Network" FALSE "Routing")


  1. Replace pipe "|" with space, and store as positional parameters

set $(echo $items | sed "s/|/ /g")

echo $* for x # Run loop for each positional parameter to launch application do

  if [ "$x" = "Kernel" ]    # Add Kernel Version to report
  then
     echo "Kernel Version: $(uname -rv)"  >> /root/report.txt
     echo  >> /root/report.txt
  fi
  if [ "$x" = "Processes" ]    # Add Kernel Version to report
  then
     echo "Process Information:"  >> /root/report.txt
     echo  >> /root/report.txt
     ps -ef  >> /root/report.txt
     echo  >> /root/report.txt
  fi
  if [ "$x" = "Hostname" ]    # Add Kernel Version to report
  then
     echo "Hostname: $(hostname)"  >> /root/report.txt
     echo  >> /root/report.txt
  fi
  if [ "$x" = "Network" ]    # Add Kernel Version to report
  then
     echo "Network Interface Information:"  >> /root/report.txt
     echo  >> /root/report.txt
     ifconfig  >> /root/report.txt
     echo  >> /root/report.txt
  fi
  if [ "$x" = "Routing" ]    # Add Kernel Version to report
  then
     echo "Routing information:"  >> /root/report.txt
     echo  >> /root/report.txt
     route -n  >> /root/report.txt
     echo  >> /root/report.txt
  fi

done

echo echo "Report has been saved in /root/report.txt" zenity --info --text "Report has been saved in /root/report.txt\n\nHave a Nice Day..."

  1. End of Bash Shell Script