How to run script on startup and shutdown OS X El Capitan Actually I want to make a RAM drive related to this script on my Mac.

Here is what I did:  


Disabled SIP in recovery mode using command "csrutil"  
Created a plist file in /Library/LaunchDaemons/
and entered launchctl -w /Library/LaunchDaemons/vn.magik.ramdisk.plist

&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt;
&lt;plist version="1.0"&gt;
    &lt;dict&gt;
        &lt;key&gt;Label&lt;/key&gt;
            &lt;string&gt;vn.magik.ramdisk&lt;/string&gt;
        &lt;key&gt;ProgramArguments&lt;/key&gt;
            &lt;array&gt;
              &lt;string&gt;/Users/khacpm/ramdisk.sh&lt;/string&gt;
            &lt;/array&gt;
        &lt;key&gt;RunAtLoad&lt;/key&gt;
            &lt;true/&gt;
        &lt;key&gt;StandardOutPath&lt;/key&gt;
            &lt;string&gt;/Users/khacpm/ramdisk.log&lt;/string&gt;
        &lt;key&gt;StandardErrorPath&lt;/key&gt;
            &lt;string&gt;/Users/khacpm/ramdisk.err&lt;/string&gt;
    &lt;/dict&gt;
&lt;/plist&gt;

Created .sh file and put it in ~/ramdisk.sh

code:

function fstartup()
{
    //put folder into ramdisk
}
function fshutdown()
{
    //detach ramdisk
}

function framdisk()
{
    //do something
}
trap fshutdown SIGTERM
trap fshutdown SIGKILL
fstartup;



The problem is, the function fstartup runs well but it seems like function fshutdown isn't called by the system.
I believe the correction to the shell script should be:

function fstartup()
{
    //put folder into ramdisk
     tail -f /dev/null &amp;
     wait $!
}
function fshutdown()
{
    //detach ramdisk

}

function framdisk()
{
    //do something
}
trap fshutdown SIGTERM
trap fshutdown SIGKILL
fstartup;


So that it will wait during the startup, not the shutdown.

I'm currently running my version and it appears to work fine, it correctly runs the shutdown function when the computer is shutting down.