How to execute a command when system boots?

Hi all,

I want to execute a command when system boots. I tried to edit /etc/rc.common and add my command at the end of rc.common, but it does not work!
Anyone knows how to do it?
Thanks :slight_smile:

First of all you need to give the command that you want to execute.. Give more information about wat you want to do exactly with the command, so we can give the best answer for wat your search to know ?

I want to create a ram disk when the system boots. The following is the command:
diskutil erasevolume HFS+ 'ramdisk' `hdiutil attach -nomount ram://262144`
Everytime I want to create a ram disk, I have to execute this command. Now I am wondering if there is a way to executing this command during system startup.

In general, you want to use launchd to create startup items in OSX.

See here (link obfuscated since I'm too new to post links): ttp://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man8/launchd.8.html

Do you want it to run 1) globally at every boot regardless of any users logging in or not, 2) only when a user logs in, or 3) only when specific users log in?

The answer is launchd and it is quite easy, but I need more info to give you an example.

I am the only user of this machine. So I guess I will choose (1).
Could you give me an example? I would like to create a ram disk when system starts up, so that I can use it as a temp folder. The command is:
diskutil erasevolume HFS+ 'ramdisk' `hdiutil attach -nomount ram://262144`

Thanks!

Launchd is a lot like cron, but more. You can Google for an app called Lingon, which will help you generate launchd items. You would just need to make a system deamon that runs your command and toss your plist file in /Library/LaunchdDaemons, then use launchctl to load it and you are set.

Here is an article explaining it

AFP548 - launchd in Depth

1 Like