|
|
#1 |
|
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
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 Thanks, Last edited by tlarkin; 09-19-2007 at 01:43 AM. |
|
|
|
|
|
#2 |
|
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 |
|
|
|
|
|
#3 |
|
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. |
|
|
|
|
|
#4 |
|
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 |
|
|
|
|
|
#5 |
|
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 |
|
|
|
|
|
#6 |
|
League Commissioner
Join Date: Mar 2003
Location: Bay Area, CA
Posts: 11,352
|
Or set textedit to plain text, not rich text.
|
|
|
|
|
|
#7 |
|
All Star
Join Date: Apr 2005
Posts: 520
|
Doh, you're right! Sorry about that...my brain kernel panicked
__________________
John Musbach |
|
|
|
|
|
#8 |
|
League Commissioner
Join Date: Mar 2003
Location: Bay Area, CA
Posts: 11,352
|
It's OK, I did the same thing with text edit.
|
|
|
|
![]() |
|
|