Wednesday, October 14, 2009

Linux System Info

# THIS IS A INTERACTIVE PROGRAM TO DISPLAY YOUR SYSTEM INFORMATION. # TYPE ./sysinfo --help FOR OPTIONS

# THE WHOLE SCRIPT CAN BE BROADLY DIVIDED INTO 3 MODULES - #################################################################################################################### MODULE 1:- ## THIS IS RESPONSIBLE FOR CLEAN UP JOBS AND ALSO PERFORMS EXCEPTION HANDLING. ####################################################################################################################

if [ "$?" -eq 0 ]thengui_support=yelsegui_support=nclearecho -e "\nInitializing Graphical Mode... Failed!!\nThis can even happen if you press Esc during initialization of graphical mode.\nThe program will run in text mode\n\n"echo "Press Enter to continue...."readfi

fi

}

# PRINTERR IS FOR TAKING THE NECESSARY ACTION IF AN ERROR OCCURS. IT PRINTS AN ERROR MESSAGE DEPENDING ON# THE FIRST ARGUMENT AND THEN EITHER EXITS AFTER GENERATING A BUG REPORT AFTER GETTING PERMISSION FROM THE# USER RUNNING THE SCRIPT WITHIN THE USER'S HOME DIRECTORY UNDER THE NAME "bug_report_sysinfo" OR SIMPLY# RETURNS TO THE POINT WHERE THE EXCEPTION OCCURED DEPENDING UPON THE SECOND ARGUMENT.printerr(){

case "$1" in"1")if [ "$gui_support" = 'y' ]thendialog --colors --title "\Z1$TITLE" --backtitle "Author - Rajat Patel, Yeswedeal" --msgbox "\n\Z1Sorry, I was unable to retrieve the required information from your system.\nPOSSIBLE CAUSE OF ERROR AND SOLUTION :-\nIt seems that the proc filesystem is not enabled in the kernel - Run script after enabling it.If it is enabled then it may not be mounted - Run script after mounting it. If it is mounted then you do not have enough permissions to retrieve information from it - Run the script as root." 19 72elseecho -e "\nSorry, I was unable to retrieve the required information from your system.\nPOSSIBLE CAUSE OF ERROR AND SOLUTION :-\nIt seems that the proc filesystem is not enabled in the kernel - Run script after enabling it.If it is enabled then it may not be mounted - Run script after mounting it. If it is mounted then you do not have enough permissions to retrieve information from it - Run the script as root."echo -e "\nPress Enter to continue..."readfi;;"2")if [ "$gui_support" = 'y' ]thendialog --colors --title "\Z1$TITLE" --backtitle "Author - Rajat Patel, Yeswedeal" --colors --msgbox "\n\Z1Sorry, I was unable to retrieve the required information from your system.\nPOSSIBLE CAUSE OF ERROR AND SOLUTION :-\nEither your system does not support showing the details you are looking for or you do not have enough permissions to do that. If you are not root try runnig the script with root priviledge." 19 72elseecho -e "\nSorry, I was unable to retrieve the required information from your system.\nPOSSIBLE CAUSE OF ERROR AND SOLUTION :-\nEither your system does not support showing the details you are looking for or you do not have enough permissions to do that. If you are not root try runnig the script with root priviledge."echo -e "\nPress Enter to continue..."readfi;;"3")if [ "$gui_support" = 'y' ]thendialog --colors --title "\Z1$TITLE" --backtitle "Author - Rajat Patel, Yeswedeal" --colors --msgbox "\Z1Sorry, I was unable to retrieve the required information from your system.\nPOSSIBLE CAUSE OF ERROR AND SOLUTION :-\nIt seems you do not have enough permissions. Try runnig the script with root priviledge." 19 72elseecho -e "Sorry, I was unable to retrieve the required information from your system.\nPOSSIBLE CAUSE OF ERROR AND SOLUTION :-\nIt seems you do not have enough permissions. Try runnig the script with root priviledge."echo -e "\nPress Enter to continue..."readfi;;

if [ "$gui_support" = 'y' ]thendialog --colors --title "\Z1ERROR" --backtitle "Author - Rajat Patel, Yeswedeal" --msgbox "\Z1A log file -- $TMPLOG was created. This happened because I faced some problem during my execution. If you suspect a bug, report it to the author at sending him the log file alongwith." 19 72elseecho -e "A log file -- $TMPLOG was created. This happened because I faced some problem during my execution. If you suspect a bug, report it to the author at sending him the log file alongwith."echo -e "\nPress Enter to continue..."readfi;;"5")if [ "$gui_support" = 'y' ]thendialog --colors --title "\Z1$TITLE" --backtitle "Author - Rajat Patel, Yeswedeal" --colors --msgbox "\n\Z1Sorry, I was unable to retrieve the required information from your system.\nPOSSIBLE CAUSE OF ERROR AND SOLUTION :-\nYour system does not support showing the details you are looking for." 19 72elseecho -e "\nSorry, I was unable to retrieve the required information from your system.\nPOSSIBLE CAUSE OF ERROR AND SOLUTION :-\nYour system does not support showing the details you are looking for."echo -e "\nPress Enter to continue..."readfi;;*)if [ "$gui_support" = 'y' ]thendialog --colors --title "\Z1ERROR" --backtitle "Author - Rajat Patel, Yeswedeal" --msgbox "\n\n\Z1It seems someone has modified this script. Please do not report bug to author. Instead try and contact the person/media/website/agency from where you got this script." 19 72elseecho -e "\n\nIt seems someone has modified this script. Please do not report bug to author. Instead try and contact the person/media/website/agency from where you got this script."echo -e "\nPress Enter to continue..."readfi;;esac

if [ "$2" = "0" ] && [ "$ERRORSTRING" != "NULL" ]thenif [ "$gui_support" = "y" ]thendialog --colors --title "\Z1BUG REPORT GENERATOR" --backtitle "Author - Rajat Patel, Yeswedeal" --yesno "\Z1If the mentioned steps did not solve your problem then report a bug to the author. Send the bug report that is automatically generated by this script along with your system information. However do not care to report a bug if:- \nyou do not want this script to generate the bug report. Or you are running this script in a non Linux operating system. This script is written for Linux only.\nReport bugs to the author at rajat@Yeswedeal.com\n\nA bug report will be generated -- $ERRLOG. If it already exists, it will won't get overwritten, it will be appended \nMake sure you have write permission in your home directory before pressing yes\nShould this script generate a bug report? " 19 72

if [ "$?" = "0" ]then create_bug_report=yfielseecho -e "If the mentioned steps did not solve your problem then report a bug to the author. Send the bug report that is automatically generated by this script along with your system information. However do not care to report a bug if:- \nyou do not want this script to generate the bug report. Or you are running this script in a non Linux operating system. This script is written for Linux only.\nReport bugs to the author at rajat@Yeswedeal.com\n\nA bug report will be generated -- $ERRLOG. If it already exists, it will won't get overwritten, it will be appended \nMake sure you have write permission in your home directory before typing \'y\'\nShould this script generate a bug report? (y/n) ..."read create_bug_reportfi

if [ "$gui_support" = 'y' ]thendialog --clear --title "THANK YOU FOR USING THIS PROGRAM" --backtitle "Author - Rajat Patel, Yeswedeal" --msgbox "\nsysinfo Version $VERSION\nCopyright (C) 2009 Rajat Patel\nThis is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE\nAuthors:-\nRajat Patel" 15 62elseclearecho -e "\n\n\t\t THANK YOU FOR USING THIS PROGRAM\n\n"echo -e "\nsysinfo Version $VERSION\nCopyright (C) 2009 Rajat Patel\nThis is free software; see the source for copying conditions.\nThere is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE\n\nAuthors:-\nRajat Patel"echo -e "\nPress Enter to exit...."readfi

}

# END OF MODULE 1#XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX#

##################################################################################################################### MODULE 2:- ##IT IS THIS PART WHICH IS ACTUALLY RESPONSIBLE FOR DISPLAYING ALL THE INFORMATION. #####################################################################################################################

type service > /dev/null 2>&1if [ "$?" != "0" ]thenecho -e "ERROR : Service information is not available.\nYour System does not support showing this information." TITLE='ERROR - SERVICE INFORMATION NOT AVAILABLE'TRIVIALCODE=1return 5fiTITLE="SERVICE INFORMATION"

# END OF MODULE 2#XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX#

##################################################################################################################### MODULE 3:- ## THIS MODULE DISPLAYS THE VARIOUS MENUS AND TAKES INPUTS FROM THE USER #####################################################################################################################

# THIS DISPLAYS THE MENU FOR PRINTING USER INFORMATIONuserinfo_menu(){