Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Install an enhanced SMART monitoring package UNIX
Unfortunately, I've recently had reason to want to check the SMART status of my PowerBook's internal disk. Apple's Disk Utility will tell you a simple pass/fail summary of the SMART status of the disk, but it won't go into any detail, show you logs, or details of particular errors. What's more, I believe that it only looks at certain classes of errors to determing the Verified of Failing status, and so if the drive is experiencing errors, such as its firmware silently remapping sectors, it's still shown as A-OK.

I decided to go hunting for some more useful utilities, and first discovered SMARTReporter which displays an icon in the menu bar showing you a visual status of the disk. This utility, however, appears to use the same criteria as Disk Utility for determining as simple pass/fail status, so in this particular case isn't that useful to me. It is handy in a more general sense as it can monitor multiple disks, and upon a SMART failure it can do any combination of: pop up an alert dialog, execute another program or send emails to multiple addresses.

So, digging a bit deeper, I then found the smartmontools, which consist of smartctl and smartd that together will report on a whole lot of low-level SMART information, including showing the drive's error log, and other useful information. smartmontools run at the command line only, so you do have to delve into Terminal to get at it, but they provide a wealth of information that is difficult, or impossible, to get in any other way. I've got more information on them available in a recent blog posting.

What I'm going to do now is, through a bit of magic with dd and DiskWarrior, to add a line to the daily cron script to check the SMART status of my internal hard disk, and let me know if there are any errors at all, not just something that DiskUtility thinks is worthy.

[robg adds: I downloaded and installed the package (following the "install from source" instructions, and it worked as described -- ./configure, make, and sudo make install installed the package. It seems to work with the SATA drives in the Dual G5, even though the site doesn't make it clear that it will do so.]
  Post a comment  •  Comments (42)  
  • Currently 2.33 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (3 votes cast)
 
[27,783 views] Email Article To a Friend View Printable Version
A script to quote any script for use as an alias UNIX
This recent hint describes how to pause and resume a process or application. The automatic version of the hint involved a long, but single-line, perl script that I said could be made into an alias. However, that's easier said than done, since the script contains so many special symbols you have to escape them properly. Therefore, this hint is actually a standalone helper hint. If you want to make an alias out of a perl command or other complex script, you can let perl do it for you like this:
perl -we '$s=;print quotemeta $s'
Run this, then type (or paste) in any command, and it will print out an escaped version of the entered code that can then be aliased.
read more (295 words)   Post a comment  •  Comments (7)  
  • Currently 1.57 / 5
  You rated: 3 / 5 (7 votes cast)
 
[5,223 views] Email Article To a Friend View Printable Version
Pause and resume resource-intensive apps via script UNIX
Occasionally I find my computer tied up with some long-duration, resource-intensive application that one can't simply quit in the middle of. For example, iDVD can run for a couple days. Other times, on my family's multi-user machine, I'd like to be able to turn off other switched-out user's resource-hungry but idle apps (e.g. Word) that cause glitches when I'm doing something like using VLC Player or watching a QuickTime 480p movie.

Rather than quiting the app, I pause and later resume it by sending it Unix signals from the command line:
kill -s STOP 3328
The above command sends the STOP signal to, in this example, process 3328, which immediatly sleeps the process without aborting it. When I am ready to resume, I send it another signal to continue:
kill -s CONT 3328
Now you might be wondering why not simply use the commands nice and renice? Well two reasons. First, and primarily because, even at nice 19, sometimes that is not affirmative enough, espcially when the process is consuming resources other than the CPU: e.g. network intensive or disk intensive operations. Second, it's tricky to undo nicing and be sure you got it right.

[robg adds: We covered stopping processes in this earlier hint. This hint, however, provides an automated solution based on processor load -- read on for the details. Note that I have not tested this one.]
read more (461 words)   Post a comment  •  Comments (11)  
  • Currently 2.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (4 votes cast)
 
[11,961 views] Email Article To a Friend View Printable Version
View upcoming events on multiple Unix calendars UNIX
I've been leeching off MacOSXHints for years; this is such a great site. So I think it's about time I share some of my own work. This hint was written because I wasn't entirely happy with the output of previous hints, so I kept working at it until I came up with this solution. I wanted a way to view upcoming entries on the various Unix calendar pages -- both the stock calendars, as well as one of my own. Here's what I eventually came up with:

#!/bin/sh
calendar -f /usr/share/calendar/calendar.computer -l 0 > ~/tmpcal.txt
calendar -f /usr/share/calendar/calendar.usholiday -l 0 >> ~/tmpcal.txt
calendar -f /usr/share/calendar/calendar.birthday -l 0 >> ~/tmpcal.txt
calendar -f /usr/share/calendar/calendar.christian -l 0 >> ~/tmpcal.txt
calendar -f /usr/share/calendar/calendar.freebsd -l 0 >> ~/tmpcal.txt
calendar -f /usr/share/calendar/calendar.history -l 0 >> ~/tmpcal.txt
calendar -f /usr/share/calendar/calendar.music -l 0 >> ~/tmpcal.txt
calendar -f ~/.calendar/calendar -l 14 >> ~/tmpcal.txt

cat ~/tmpcal.txt | sort -M
rm ~/tmpcal.txt

The explanation:

Each line that begins with calendar looks up date information in a different calendar file. The -f switch precedes the full path to a calendar file (most of which are in /usr/share/calendar, but you may also have personal ones elsewhere). The -l switch precedes the number of days to look ahead. When look ahead is set to 0, then only today's date information is returned. The tail end of each calendar line directs the input to a temporary file (the >> on all but the first line amends the output to the file created in the first line). The last calendar line looks in my personal file (in my home directory), which contains personal dates of importance.

The line which begins with cat lists the temporary file, and then directs the output to the sort util. sort then uses the first portion of the line to sort by date (so if your information spans one or more months, it should sort properly -- I've done a limited test on this). The last line removes the temporary file.

[robg adds: I tested this, and it seems to work as described. Remember to make the script executable after saving (via chmod a+x scriptname).]
  Post a comment  •  Comments (13)  
  • Currently 3.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (2 votes cast)
 
[6,170 views] Email Article To a Friend View Printable Version
Set the title of the Terminal window with cd UNIX
Terminal lets you set the window title with some interesting options, but alas not the current directory. I wanted to move the current directory from the prompt to the window title. The downside is that you cannot copy the current working directory without typing pwd, but there are several upsides.

First there is the settitle function, which someone else wrote:
function settitle() { echo -ne "\e]2;$@\a\e]1;$@\a"; }
This changes the title of the current window. In Terminal, this is the string you can set in the Window Settings that defaults to "Terminal" but not the whole window title.

Next there is a new cd function to replace the built in command:
function cd() { command cd "$@"; settitle `pwd -P`; }
Using command before cd forces bash to use the built-in instead of the function, so no infinite loop on cd. You could pass anything to settitle; this passes the current full path without links.

To make this complete, change the prompt to remove the redundant path:
default: '\h:\w \u\$ '
export PS1='\h:\W \u\$ '
export PS1='\h:\u\$ '
The default is to have the full path after the hostname. The first option reduces the full path to the name of the current directory. The second option removes the path altogether.

Finally, if you want to be consistent, add the following line somewhere so that when the shell starts the title is set. Otherwise the title will be "Terminal" or whatever is set in the Window Settings until cd is called. Of course, you may prefer that.
settitle `pwd`
There are a lot of variations on how the path is derived and displayed, and what other information would be useful in the window title. Here is one last example that more closely matches the information in original prompt:
"${HOSTNAME%%.*}:${PWD/$HOME/~} $USER"
I assume that most people who would care about this also know where to place the above commands. But just in case, stick all the above code in either .bashrc or .profile in the home directory.

[kirkmc adds: We've run other hints on changing Terminal window titles, including this hint and this hint, both of which give different methods for putting the current directory in the window title. This is another way, and may interest some readers just because it's different.]
  Post a comment  •  Comments (11)  
  • Currently 2.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (4 votes cast)
 
[26,032 views] Email Article To a Friend View Printable Version
osascript, shebang, and unicode arguments UNIX
I am Polish and I have files whose names contain Polish characters. One day I was horrified to find that I could not pass such a file to an AppleScript. After much work, I finally figured out a way to pass arguments containing international characters to an AppleScript. Along the way, I learned many other things as well. I will explain this starting with simple examples, then expanding on them. In this hint you will learn the the magic shebang for an AppleScript, and some useful rules for Makefiles, in addition to the main hint itself, with an example script that opens files in Preview.

I wanted a way to run an AppleScript from the command line using the Unix shebang approach. An example of what I wanted is having the first line of a Bourne shell script be #!/bin/sh. In this way, you can simply type the name of the script in Terminal to launch it. I wanted a similar approach for an AppleScript.

[kirkmc adds: Wow, what a hint! I have to admit, my AppleScript skills are too limited to follow all of this one, but the poster went to no end to explain this in detail. What follows are nearly 4,000 words on the subject, so read on if you're interested in the very fine details.]
read more (3,426 words)     •  Comments (7)  
  • Currently 2.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (3 votes cast)
 
[21,177 views] Email Article To a Friend View Printable Version
10.4: Build a GCC 3.3 C compiler for Intel Mac OS X UNIX
Tiger only hintI use a GCC cross compiler for embedded systems development on my Mac. I use Apple's supplied GCC to build the cross toolchain, but when Apple started using GCC 4.0.x, I could no longer compile the specific version of binutils and GCC that I need.

On PowerPC Macs, I could revert to Apple's GCC 3.3 to compile my toolcain, but on my new Macbook Pro, Xcode does not come with GCC 3.3. It is my understanding that Apple will not be providing a GCC 3.3 for Intel OS X.

Fixing my toolchain to compile with GCC 4.0.x is not an option, because the tools are under configuration management and build fine on all of the other computers in my organization ( cygwin and linux ).

After much expermenting, I finally was able to build Apple's GCC 3.3 so I could then build an Intel OS X hosted version of my cross toolchain.

Here is what I did: 1. Download the source code for Apple's GCC 3.3 in Xcode 2.2 here. Get the file named gcc_os-1819.tar.gz

2. Unpack the source.

$ tar -zxf gcc_os-1819.tar.gz

3. Fix a line that causes it to not compile: in the file gcc_os-1819/gcc/gcc.c, on line 5883, change the line to look like this:

(char ) v[q - vt] = 0;

4. Make a build directory and run configure. I installed my compiler in /opt/gcc3, and I only built the C compiler. This would not work for building C++ or Cocoa applications.
$ mkdir build
$ cd build
$ ../gcc_os-1819/configure --prefix=/opt/gcc3 --enable-languages=c
5. Build the compiler:

$ make all

6. Install the compiler in /opt/gcc3:

$ sudo make install

7. Test it:
$ /opt/gcc3/bin/gcc -v
Reading specs from /opt/gcc3/lib/gcc-lib/i686-apple-darwin8.6.1/3.3/specs
Configured with: ../gcc_os-1819/configure --prefix=/opt/gcc3 --enable-languages=c
Thread model: single
gcc version 3.3 20030304 (Apple Computer, Inc. build 1819)
Now, you can use the compiler to build Unix packages that will not build with GCC 4.0.x.

[kirkmc adds: I haven't tested this.]
  Post a comment  •  Comments (10)  
  • Currently 2.50 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (2 votes cast)
 
[25,825 views] Email Article To a Friend View Printable Version
Solaris / SysV Style ps UNIX
I come from a Solaris background, and my fingers can't seem to get used to typing ps -aux instead of ps -ef. So I wrote this script called ps-ef to save some sanity and format the ps output as close to Solaris style as I could. It will pass on any options to OS X's ps, so something like ps-ef -ww will work too. Just make it executable (chmod +x and put it somewhere in your path.
#!/bin/bash
pformat="user=UID,pid,ppid,cpu=C,start=STIME,tty,time,command"
psarglist=
psarglistlong=
while true ; do
        if [ -z "$1" ]; then
                break;
        fi
        optchar=${1:1}
        case $optchar in
                O|o|p|t|U)
                        shift
                        psarglistlong="$psarglistlong -$optchar $1"
                ;;
                *)
                        psarglist="$psarglist$optchar"
                ;;
        esac
        shift
done
ps -ax$psarglist $psarglistlong -o $pformat
  Post a comment  •  Comments (5)  
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[8,301 views] Email Article To a Friend View Printable Version
10.4: Fix a command-line FTP problem with IPv4 servers UNIX
Tiger only hintI sometimes use the command-line FTP program that's included with Mac OS X to upload files to my ISP. Since Tiger was released, I have had problems. The login process always works fine, but when I try to do a dir command, for example, the program stalls and I never get the results.

For a while I suspected my Linksys router to be the problem. But I tried the same FTP commands on a Linux box I have, and everything worked fine. So it really is a Tiger issue.

After some investigation, I found that Tiger's FTP program has an option set by default: EPSV/EPRT on IPv4. To disable this, you must issue the epsv4 command in the FTP program before doing anything else. From now on, any command will work correctly and as expected.

[kirkmc adds: The man page for the ftp command mentions this option and command. It seems that the option exists in Panther, but was not enabled by default.]
  Post a comment  •  Comments (9)  
  • Currently 3.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (2 votes cast)
 
[10,980 views] Email Article To a Friend View Printable Version
Create multiple folders from Terminal UNIX
I needed to create a new folder for each of a list of customers, and knew there had to be a better way than doing it manually. So I looked at the mkdir command, which creates new folders or directories. It uses the following syntax:
mkdir folder1 folder2 folder3
I tried redirecting a file with a list of folder names into mkdir with no success, so I ended up just copying and pasting my list into Terminal. You cannot use a list with returns; all the names need to be on one line, separated by spaces.

[kirkmc adds: While this is a pretty basic hint, it shows some interesting things that you can do from Terminal. First, you need to tweak your list of customers (or whatever) so all the names are on one line. Next, you need to worry about spaces: if you have names with spaces, the names need to be in quotes, such as "Henry David Thoreau"; otherwise, you'd get individual folders named Henry, David and Thoreau. You could also use underscores (Henry_David_Thoreau), or other characters as separators.

For example:
$ mkdir "Henry David Thoreau" Ralph_Waldo_Emerson Walt-Whitman
The above command makes a total of three new folders, the first separated by spaces, the second by underscores, and the third with a hyphen; the only constraints are the actual tweaking of your list. You may need to take a tab- or return-delimited list and replace the tab or returns, or manually add quotes, but you can use this to create any number of folders very quickly.]
  Post a comment  •  Comments (36)  
  • Currently 3.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (2 votes cast)
 
[30,005 views] Email Article To a Friend View Printable Version