How to execute a command when system boots?


 
Thread Tools Search this Thread
Operating Systems OS X (Apple) How to execute a command when system boots?
# 1  
Old 03-25-2011
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 Smilie
# 2  
Old 03-26-2011
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 ?
# 3  
Old 03-26-2011
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.
# 4  
Old 03-27-2011
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
# 5  
Old 04-05-2011
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.
# 6  
Old 04-07-2011
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!
# 7  
Old 04-09-2011
Quote:
Originally Posted by andrewust
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
This User Gave Thanks to tlarkin For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Red Hat

Systemd booting and execute system command is Not successful!help!

hi guys, booting centos7 and use systemd execute system command ulimit -SHn 202400 is fail.i dont know what's reason.can you give me help. ------------------------------------------ set-ulimit.service Description=test service After=systemd-update-utmp-runlevel.service #the last... (1 Reply)
Discussion started by: shean
1 Replies

2. Solaris

Solaris 10 system boots into Maintenance mode

I have seen similar threads on this issue, but I have not seen a fix. Basically I am getting a lot of rcp bind errors. Below find the output of "svcs -xv". not sure where to begin: # svcs -xv svc:/network/rpc/bind:default (RPC bindings) State: maintenance since Fri May 25 14:13:18 2012... (14 Replies)
Discussion started by: brownwrap
14 Replies

3. Ubuntu

execute command when Ubuntu boots up ?

hey all,, I want to add comments when Ubuntu starts up.. now I know that there is a directory called /etc/init.d which I can place my scripts there to run them at Ubuntu's startup.. but I prefer if there would be a file which runs when Ubuntu starts!! because it is only one command. not... (2 Replies)
Discussion started by: eawedat
2 Replies

4. Shell Programming and Scripting

Execute shell script in different system

Hi, I have a shell script in systemA and another shell script in systemB. when I execute the script in systemA, it should call the another script in systemB. Please tell me the way to do this. Thanks, Raja. (3 Replies)
Discussion started by: smr_rashmy
3 Replies

5. Shell Programming and Scripting

How to execute piped command using exec or system

Hi All, I want to execute a piped command like 'ls /opt | grep xml' using array as parameters list. How can I do that? (2 Replies)
Discussion started by: bharadiaam
2 Replies

6. Programming

c++ : Use of System() to execute .exe with parameters

Hello, I 've trie to execute a a program with parameters unsuccessfully and i take the above message : "The system cannot find the path specified." I used a variaton of the above command : system("\"C:\\xxx\\xxx\\xxx.exe -xxx -xxx xxx.xxx xxx.xxx xxx.xxx\""); Thanks in advance (4 Replies)
Discussion started by: eusta
4 Replies

7. UNIX for Advanced & Expert Users

How to remotely execute a script (.COM ) on a VMS system ?

How to remotely execute a script (.COM ) on a VMS system ? rsh ? Thanks in advance (1 Reply)
Discussion started by: ivancleber
1 Replies

8. AIX

Execute a command at the system restart

Hi Folks, I have an AIX server and I would like the server to run the command saprouter -r at every system restarts. It needs to be run by a specific user. How would I do that? Thanks!!! (1 Reply)
Discussion started by: brookingsd
1 Replies

9. UNIX for Advanced & Expert Users

AIX 433 boots into command line.

Hi All, I have an AIX 433 workstation that keeps booting into command mode. It was booting into CDE for a long time now. Suddenly now it boots into command line mode. No errors while booting up. Do not see anything in errpt. Don' t know where to start from.. Can any one please help me..thanks. ... (2 Replies)
Discussion started by: navinxavier
2 Replies
Login or Register to Ask a Question