Go Back   The macosxhints Forums > OS X Help Requests > System



Reply
 
Thread Tools Rate Thread Display Modes
Old 09-19-2007, 01:11 AM   #1
tlarkin
League Commissioner
 
Join Date: Mar 2003
Location: Bay Area, CA
Posts: 11,352
Diagnostics script

Well, I wrote a diagnostic script mainly for this forum when i was teaching myself shell scripting for a project at work. I submitted it as a hint, but figured I would post it here on the forum as well with some more detailed instructions on how to run it. It has some useful options and I tried to put in a lot of commands that hayne would possibly ask an inexperienced user when it comes to BASH and the the terminal.

This script assumes a few things, it assumes that your account is part of the admin group, so I suggest running this as admin, if not you will need to modify a few things with sudo in the script itself. If you do not run as admin in your mac account then you will need to add sudo the log files commands. This also assumes you have not changed anything in your default $PATH

here is the original hint: http://www.macosxhints.com/article.p...y=tom%2Blarkin

Here is the script:
Code:
#!/bin/bash

#This is a menu for basic diagnostics by Thomas Larkin

echo "Hello $USER, Welcome to the Tom's Diagnostic script!"
echo "Today is  ";date
echo "Number of user logged in : " ; who | wc -l
echo "Calendar"
cal

selection=
until [ "$selection" = "0" ]; do
    echo ""
    echo "Select an option please"
    echo "1 - Display all objects in /Volumes"
    echo "2 - Display total disk usage of /, this may take a while.  You will be prompted for admin access"
    echo "3 - Display the disk usage of my Home Directory, this may take a while"
    echo "4 - Print the contents of /var/log/system.log"
    echo "5 - List all current users logged in this computer"
    echo "6 - Display my Network Settings and Information"
    echo "7 - Display my BASH command paths"	
    echo "8 - Display all the current running processes"
    echo "9 - Display current resources being used"	
    echo "10 - Display the print error log"
    echo "11 - Display the crash reporter log"
    echo "12 - Run Verify permissions on the boot volume"	
    echo "13 - Run Repair Permissions on the boot volume"
    echo "14 - Run verify volume on the boot volume"
    echo "15 - list all information of boot volume"
    echo "0 - exit program"
    echo ""
    echo -n "Enter selection: "
    read selection
    echo ""
    case $selection in
           1 ) /bin/ls -al /Volumes ;;
           2 ) sudo /usr/bin/du -h -x  / | sort ;;
           3 ) /usr/bin/du -a -h -x  /Users/$USER | sort ;;
	   4 ) /bin/cat /var/log/system.log ;;
	   5 ) /usr/bin/finger -h ;;
	   6 ) /sbin/ifconfig ;;
	   7 ) /bin/echo $PATH ;;
	   8 ) /bin/ps -A ;;
	   9 ) /usr/bin/top -s5 20 ;;
          10 ) /bin/cat /var/log/cups/error_log ;;
          11 ) /bin/cat /var/log/crashreporter.log ;;
          12 ) /usr/sbin/diskutil verifyPermissions / ;;
          13 ) /usr/sbin/diskutil repairPermissions / ;;
          14 ) /usr/sbin/diskutil verifyVolume / ;;
          15 ) /usr/sbin/diskutil list / ;;
	   0 ) exit ;;
       * ) echo "Please enter a valid option"
    esac
done
If your account is not part of the admin group you will need to add a sudo to all the commands that print log files. There are some little features I added in like a calendar and it lists what users are currently logged in (for all you paranoids) and then it lists a set of options.

But first....Copy and paste the script into a text editor. make sure you save it as plain text, not rtf. Then I recommend you save it as diag.sh for example and toss it into your documents folder. I like to use the .sh extension so it tells me that the file I am looking at is a script. It will ask you if you are sure you want to use the .sh extension, say yes. You own this file since you created it, so by default you should already have sufficient permissions to run it. Now you should have all this code copied into a plain text file and saved in your Documents directory as diag.sh.

Now open up terminal.app, and simply type sh then the path to your script, or alternatively, type sh and then drag the script file onto the terminal window, and it should copy the path to the file. you will then run my scripted diag program and can execute the commands

example:
Code:
sh /Users/tlarkin/Documents/diag.sh
To the Mods of this forum....I almost added this into the OS X troubleshooting thread but wanted to get some feed back and possibly some advice from people using it to see if it is actually worth adding to the OS X troubleshooting list? I will also try to update it after leopard comes out to make it more up to date, and there is no intel section either. So, let me know if this is a good idea for a script or not and why.

Thanks,

Last edited by tlarkin; 09-19-2007 at 01:43 AM.
tlarkin is offline   Reply With Quote
Old 09-19-2007, 01:33 AM   #2
hayne
Site Admin
 
Join Date: Jan 2002
Location: Montreal
Posts: 32,473
Looks like a useful script.

But it is always a good idea to use the full paths for executable and files that you are referring to in a script.
E.g. use '/bin/cat' instead of just 'cat'
This is especially true when the script will be used by others.

Otherwise there is a possibility that there will be an executable in the user's PATH that is named the same as what you have referred to in the script, but which does something completely different.

For example, run the following (composite) command (in a Terminal window) and then try running your script and choosing #4:
Code:
echo "say mee-ow" > cat; chmod +x cat; export PATH=".:$PATH"
__________________
hayne.net/macosx.html
hayne is offline   Reply With Quote
Old 09-19-2007, 01:44 AM   #3
tlarkin
League Commissioner
 
Join Date: Mar 2003
Location: Bay Area, CA
Posts: 11,352
Okay, i was afraid there would be those who have changed the $PATH, but I edited the script and added the disclaimer it assumes you have not edited your $PATH at all.

Thanks for the input.

Last edited by tlarkin; 09-19-2007 at 01:47 AM.
tlarkin is offline   Reply With Quote
Old 09-21-2007, 01:39 AM   #4
maclova
All Star
 
Join Date: Apr 2005
Posts: 520
script is broken!!

computer:~/desktop hexstar$ ./test.sh
./test.sh: line 1: {rtf1macansicpg10000cocoartf824cocoasubrtf420: command not found
./test.sh: line 2: syntax error near unexpected token `}'
./test.sh: line 2: `{\fonttbl\f0\fswiss\fcharset77 Helvetica;}'
__________________
John Musbach
maclova is offline   Reply With Quote
Old 09-21-2007, 01:43 AM   #5
trevor
Moderator
 
Join Date: Jun 2003
Location: Boulder, CO USA
Posts: 19,854
You have to use a text editor, not an rtf editor. And your text editor has to use Unix line endings.

Trevor
trevor is offline   Reply With Quote
Old 09-21-2007, 02:09 AM   #6
tlarkin
League Commissioner
 
Join Date: Mar 2003
Location: Bay Area, CA
Posts: 11,352
Or set textedit to plain text, not rich text.
tlarkin is offline   Reply With Quote
Old 09-21-2007, 10:15 PM   #7
maclova
All Star
 
Join Date: Apr 2005
Posts: 520
Doh, you're right! Sorry about that...my brain kernel panicked
__________________
John Musbach
maclova is offline   Reply With Quote
Old 09-22-2007, 09:15 AM   #8
tlarkin
League Commissioner
 
Join Date: Mar 2003
Location: Bay Area, CA
Posts: 11,352
It's OK, I did the same thing with text edit.
tlarkin is offline   Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 10:13 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.