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

Revisiting Terminal.app's [Process completed] bug UNIX
After reinstalling my iBook from scratch this weekend, I started suffering (occasionally) from the old [Process completed] bug, as mentioned in this earlier hint.

Unfortunately, all the suggested fixes seem to be failing for me, including an upgrade to a newer zsh. As a user of zsh for the past ten years or so, I'm certainly not going to change shells, which made me think of this approach. It also gives me the joy of abusing both csh and dtterm at the same time. The principle is to use csh to bootstrap zsh, utilizing an obscure terminal type to signal csh to do so. At the command prompt (if you can get one -- I was having this problem only occasionally), execute:
    echo 'if ($TERM == dtterm) then' >> ~/.cshrc
    echo '    set term=xterm-color' >> ~/.cshrc
    echo '    exec zsh' >> ~/.cshrc
    echo 'endif' >> ~/.cshrc
Then in Terminal Preferences, set "Execute the command (specify complete path)" to /bin/csh -l and "Declare terminal type ($TERM) as" to dtterm.

Of course, if you're unfortunate enough to have to still use dtterm emulation at any time, you'll have to substitute one of the other predefined terminal types.
  Post a comment  •  Comments (6)  
  • Currently 2.00 / 5
  You rated: 4 / 5 (4 votes cast)
 
[8,750 views] Email Article To a Friend View Printable Version
Fix missing man pages for self-installed utilities UNIX
The rule is to install any custom UNIX utilities in /usr/local, but unfortunately due to the way man is set up, the man pages for things installed in /usr/local may not be found.

The problem is that the man configuration file (/usr/share/misc/man.conf) defines a number of MANPATH_MAP directives. Here are some of them:
MANPATH_MAP    /usr/bin                /usr/share/man
MANPATH_MAP    /usr/sbin               /usr/share/man
MANPATH_MAP    /usr/local/bin          /usr/local/share/man
This means, for instance, that if you type man grep, man examines your PATH variable and finds that the grep executable is in /usr/bin. The MANPATH_MAP directive instructs it to look in the /usr/share/man directory to find the man page for grep. This overrides man's default behavior, which would be to look in the "nearby" directory /usr/man, which does not exist.

However, in the case of software installed in /usr/local, the man pages are more commonly (at least in my experience) installed in /usr/local/man, not /usr/local/share/man, so that MANPATH_MAP directive does the opposite of what we want.

If you keep all your /usr/local man pages in /usr/local/man rather than /usr/local/share/man, the simple solution is just to comment out that one MANPATH_MAP directory. You'll need to use sudo, since the /usr/share/misc/man.conf file is owned by root.
  Post a comment  •  Comments (11)  
  • Currently 3.25 / 5
  You rated: 3 / 5 (4 votes cast)
 
[12,332 views] Email Article To a Friend View Printable Version
Generate random passwords via a perl script UNIX
For a little while, now, I've used this Perl script to generate truly random passwords. I don't actually bother to remember them, of course -- that's what Keychain is for.

The program uses /dev/urandom as its source of randomness, which is the best source available on OS X and (essentially) what gets used to generate SSL sessions, FileVault keys, and the like. The program lets you specify the length of the password as well as the set of characters to choose from. If you use the -v flag, it'll tell you how large a keyspace you're drawing from.

You can easily use this program for one-off Web passwords. (Well, 'easily' if you're not put off by using the Terminal.) Just pipe the output to pbcopy, and then paste into the Web form; you never even have to see the password. This works in verbose mode, as well, since the messages are sent to STDERR. It might look as simple as this:
 $ genpw | pbcopy
to generate a password and put it on the clipboard, if you're happy with the defaults. Or, it might look like this if you need a password for a Web site that restricts you to eight-letter (no digits or special characters) passwords, and if you want to get an idea of just how insecure that is:
 $ genpw -vUln8
 Generating a 8-character password
 using /dev/urandom
 and the following characters:
 ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
 This password is drawn from a keyspace of 46 bits.
 ----8<----cut-here----8<----
 jtZJIjoP
 ---->8----cut-here---->8----
Full documentation and help is available through perldoc; just run perldoc genpw to have all your questions answered. This program is also BSD-licensed, so you can do almost anything you might like to do with it. Anybody who wants to wrap a GUI around it is more than welcome to do so.
  Post a comment  •  Comments (18)  
  • Currently 2.80 / 5
  You rated: 3 / 5 (5 votes cast)
 
[16,329 views] Email Article To a Friend View Printable Version
A perl script to list duplicate files UNIX
Whenever you have a collection of data files that came from several different sources, there is the possibility that some of the files are duplicates of one another. For example, you might have sound loops that came with several different products (GarageBand, Soundtrack, etc) and there is some overlap between these. If you wanted to save disk space by clearing out the duplicates, the first thing you would need to do is identify which files are duplicates of each other. This is not always easy since the filenames are often unrelated.

(There is a previous hint that supplies a script for deleting duplicate sound loops, but that script relied upon lists of the duplicates having previously been prepared. There's also a hint on finding and removing iTunes duplicates via a Perl script.)

Today's hint supplies a script that will search for duplicate files in specified folders, and output a list of the files that are duplicates of each other. (i.e. it is something that will produce the lists that were used in the first previous hint.)
read more (521 words)   Post a comment  •  Comments (10)  
  • Currently 2.60 / 5
  You rated: 3 / 5 (5 votes cast)
 
[26,382 views] Email Article To a Friend View Printable Version
A script to locate the package that created a given file UNIX
Sometimes one needs to know what package a given file belongs to. Such information is contained in Archive.bom files that are added under the /Library/Recepits directory every time a package is installed. However, it's impractical to scan this folder for all Archive.bom files.

The findutils tool locate can be used to perform the task of mapping files to packages in a much more convenient way. It's enough to build a databse containing the required information in a format that locate is able to use, and then point locate to such database.

The database will contain a tab-separated list of file/package names; to produce such list we use find to obtain the list of all Archive.bom files, lsbom to list their contents, and a bit of bash magic to paste the file and package name. Once we have the list, we just need to sort it and to front-code it (using the frcode tool, from findutils).
read more (219 words)   Post a comment  •  Comments (2)  
  • Currently 3.75 / 5
  You rated: 5 / 5 (4 votes cast)
 
[10,441 views] Email Article To a Friend View Printable Version
Track file changes to help with system recovery UNIX
With the recent advent of a possible Mac OS X virus (or trojan, depending on who you ask) many OS X users are wondering how safe they really are. Those "infected" by the so called virus are currently clueless as to what the virus has really done. Luckily, UNIX has a tool that may help find it.

The du command (disk usage) is capable of printing out a list of all the files on your Mac. Redirecting its output, you basically have a giant log of all of your files at any given time. If you do this on a regular basis, and compare the old with the new, you suddenly can see what has changed (ie: where is a virus?).

So, do this, I whipped up a little shell script. Note that I am not great with scripts, but I have tested this, and it works for me (on at least 10.4). Make a script called duscript.sh, and save it in your Home directory. This is the script:
#!/bin/sh
cd /

du > ~/duLog-`date +%Y%m%d` &
Make sure to make the file executable by typing chmod +x duscript.sh. Then, add the file to cron. I used CronniX to do this.

In CronniX, choose File: Open System Crontab. Then, click the New button in the main window. Click the Expert tab. In the below textboxes, set it to run however often you want. I have mine to run every day, at 6 PM. For Day, Day of Week, and Month, I have it set to *, and for hour, 18. You can set it to run however often you want. Then click the Browse button and select your script.

That should do it for you. The script will run in the background on your specified terms, and it will give you logs to work with if (heaven forbid) you need to clean up from a virus.

[robg adds: While this works, it will generate very large files. In a test on my G5, I wound up with a file that was nearly 20MB in size and took about 15 minutes to execute. Comparing two such files won't be very pleasant, even using FileMerge or diff.

However, given the recent activities in the malware/trojan area, I think that discussing ways to track changes to your system is an important one. Read the rest of the hint for my thoughts on one alternative method of tracking such changes...
read more (184 words)   Post a comment  •  Comments (14)  
  • Currently 3.60 / 5
  You rated: 5 / 5 (5 votes cast)
 
[14,294 views] Email Article To a Friend View Printable Version
10.4: Use Transmit with X11 emacs UNIX
Tiger only hintHaving spent €39 on TextMate and a similar amount on Transmit, I felt quite happy with my development environment. However, once an emacs user, always an emacs user (and it doesn't help that TextMate has mediocre python support, either).

I still like Transmit, though, and wanted to use it from within emacs. After some fumbling and gnashing of teeth, I came up with this solution. Note that this requires a registered version of Transmit ~2.5 or newer.
read more (203 words)   Post a comment  •  Comments (0)  
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[8,195 views] Email Article To a Friend View Printable Version
Display a tree-like structural view of any directory UNIX
First of all this is not my code, I found it on this page via Google, while looking for something that would work like the 'tree' command in Windows.

This guy found a way to do so, using just ls, grep and sed; pretty neat! Here's the command:

ls -R | grep ":" | sed -e 's/://' -e 's/[^-][^\/]*\//--/g' -e 's/^/   /' -e 's/-/|/'

The author of this useful command even provides a downloadable shell script for the code, and explains how to make a link to ~/bin/tree for those less Unix savvy users. Enjoy!

[robg adds: First, I apologize for the scrolling box, but I didn't want to take any chances on changing the format of the command by inserting a line break, and it was otherwise too wide for display. I'll be the first to admit I don't understand anything in that command past the colon-replacement bit, but it does work quite nicely. Here's a sample of the output, using the shell script from the linked page:
$ tree /Applications | more
/Applications
   |-Address Book.app
   |---Contents
   |-----MacOS
   |-----Resources
   |-------ABLargeTypeWindow.nib
   etc...
You may wish to add | more at the end to page through the output. Or try using > ~/Desktop/mytree.txt at the end to dump the output to a file. I do not, however, recommend doing that with a huge directory such as Applications, unless you have some time to wait. I tried it, and after a few minutes of waiting, wound up with a 1.1mb text file containing 37,000+ rows!]
  Post a comment  •  Comments (33)  
  • Currently 3.00 / 5
  You rated: 4 / 5 (5 votes cast)
 
[44,390 views] Email Article To a Friend View Printable Version
Use KDE and Konqueror on OS X UNIX
This seems pretty old, but I just came accross it. It looks like the OpenDarwin group has created binaries for installing KDE specific apps on OS X (the source files are also accessible elsewhere). Just visit kde.opendarwin.org/.

You need to install at least the Qt, kdesupport and kdelibs packages to begin with, so the rest of the packages will work. From there on, I also recommend kdebase and kdenetwork. Through these two packages, I have a working version of the Konqueror browser on my OS X, with all the nice protocol support (such as fish://) that comes with it.

Bugs galore, as development has stopped on these versions in favor of completing KDE4 first, and then trying to port that ... but they still work! I've managed to get them to run on OS X 10.4.4 without many problems (even though the site states that the binaries were compiled on Jaguar), and most of the apps that come with the packages seem to operate just fine (more or less -- see note below). Kile (a LaTeX front end) has a lot of niceness, and I'm experimenting with Kate (which is slow on my system, but I think I can tweak it to run satisfactorily).

I suggest using the second option on that page to download, unless you're on a really fast broadband connection, as there are over 200 megs of binaries to download if you want the full package! (I like the progress bar to know where I'm at.)

Note: As mentioned on the above linked website, these apps sometimes have problems shutting down (they don't die gracefully). To combat that, I wrote a small Terminal script that cleans up memory from all (runaway or not) KDE processes. Other than that, no Terminal usage is necessary to install/play with these applications! Copy the following snippet, save it in a location you can easily access from the Terminal, and then type chmod 755 filename to make it executable:
#!/bin/bash<br />
kill `ps aux | grep kde | grep -v grep | awk '{print $2}'`
That's it! If you name the file killkde, and you save it in your home folder, all you have to do is start the Terminal and type ./killkde to terminate all running KDE apps.
  Post a comment  •  Comments (8)  
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[18,334 views] Email Article To a Friend View Printable Version
A possible solution for a hanging ssh login UNIX
If you cannot login any longer from your Mac user's shell account to a remote server with ssh, and ssh -vvv loginname@server is hanging at the following line...
debug3: Trying to reverse map address 192.168.73.23.
..then look cd into /tmp/.KerberosLogin-xxx-yyyyy, where xxx is your Unix user ID (typically 501 for the first user created on the machine), and yyyy is a random number. Once there, remove the file named KLLCCache.lock. Try again, and bingo. Hurray!

[robg adds: On my machine, these directories also have some text following their names -- (inited,gui,tty,local), for instance.]
  Post a comment  •  Comments (5)  
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[10,029 views] Email Article To a Friend View Printable Version