sysadmin

How to enable the root user in OS X 10.5 (Leopard)

Mac OS X 10.5 or later

  1. From the Finder’s Go menu, choose Utilities.
  2. Open Directory Utility.
  3. Click the lock in the Directory Utility window.
  4. Enter an administrator account name and password, then click OK.
  5. Choose Enable Root User from the Edit menu
  6. Enter the root password you wish to use in both the Password and Verify fields, then click OK.

Copy files and directories recursively with tar

Copying a directory tree and its contents to another filesystem using


cp -pR directory /newplace

doesn't always do the job.

Using tar instead will preserve ownership, permissions, and timestamps. This neat trick allows using tar to perform a recursive copy without creating an intermediate tar file and overcoming all cp shortcomings.

To copy all of the files and subdirectories in the current working directory to the directory /target, use:


tar cf - * | ( cd /target; tar xfp -)

Leopard not booting: mDNSResponder daemon stuck

Today, after upgrading one of our machines to the latest security update, the iMac G5 stopped booting. Starting the machine in Single User mode (command+S) revealed that the mDNSResponder daemon was crashing and restarting in an infinite loop.

'The Mac was stuck in a loop trying to execute mDNSResponder (which is the basis of Bonjour networking) and the system wasn't successful.

On the Apple forums nobody is able to pinpoint the problem yet, but it looks like it is a pretty common disease. If you do not need Bonjour, this is what solved it for me:

How to rename multiple files from the shell - tips and tricks

Renaming multiple files seems to be a problem which many newcomers to shell scripting, or administration, have problems with. But once you've done it a few times the actual solutions are very simple.

There are many cases where you might have a large number of files to rename en masse, for example files which are output from a given script or tool. Or files that must be renamed to be uploaded to a web-host.

How you rename the files mostly depends on which tools you have available, and which shell you're using.

printf - formatted output (man page)

PRINTF(1) BSD General Commands Manual PRINTF(1)

NAME
printf -- formatted output

SYNOPSIS
printf format [arguments ...]

DESCRIPTION
The printf utility formats and prints its arguments, after the first,
under control of the format. The format is a character string which con-tains contains
tains three types of objects: plain characters, which are simply copied
to standard output, character escape sequences which are converted and

How to empty a MySQL database from the shell (drop all tables)

Let’s say you need to drop all tables in a mysql database. How do you do that?

MySQL has DROP TABLE and DROP DATABASE but there is no command to drop all tables or truncate the database.

These are some ways to do it:

The best way to execute PHP scripts from a cron job

Running PHP scripts within the cron environment can be tricky!

A common technique for executing PHP scripts from a cron job is to use a command line utility like curl or wget to execute and subsequently retrieve the output of the script. Using this method, the command in your cron job would look like this:

wget http://domain.tld/script.php

Recipe: How to copy files and directories recursively with tar

TAR is the Unix Tape ARchive utility. It can be used to either store data on a streaming tape device like a DAT drive, or store files in what is commonly called a tarball file - somewhat like a pkzip file, only compression is optional.

Copying a directory tree and its contents to another filesystem using tar will preserve ownership, permissions, and timestamps. A neat trick allows using tar to perform a recursive copy without creating an intermediate tar file.

To copy all of the files and subdirectories in the current working directory to the directory /target, use:

Change the default screenshot format

In the Terminal type

defaults write com.apple.screencapture type image_format
#  image_format can be jpg, pdf ,etc
killall SystemUIServer
# to implement the new screenshot format
Syndicate content