To run scripts/commands you can use launchd.
You need to have 2 files specifically.
1) Your shell scripts.
2) plist file.
Here is the sample plist: Save it as com.example.exampld.plist. Label and plist names are preferred to be given same by apple.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.example.exampled</string>
<key>LaunchOnlyOnce</key>
<true/>
<key>ProgramArguments</key>
<array>
<string>/bin/sh</string>
<string>absolute_path_to_script</string>
</array>
</dict>
</plist>
And place it in the according to your need.
Here are the folders:
|------------------|-----------------------------------|---------------------------------------------------|
| User Agents | ~/Library/LaunchAgents | Currently logged in user
|------------------|-----------------------------------|---------------------------------------------------|
| Global Agents | /Library/LaunchAgents | Currently logged in user
|------------------|-----------------------------------|---------------------------------------------------|
| Global Daemons | /Library/LaunchDaemons | root or the user specified with the key UserName
|------------------|-----------------------------------|---------------------------------------------------|
| System Agents | /System/Library/LaunchAgents | Currently logged in user
|------------------|-----------------------------------|---------------------------------------------------|
| System Daemons | /System/Library/LaunchDaemons | root or the user specified with the key UserName
|------------------|-----------------------------------|---------------------------------------------------|
According to your need place it either in 1st or 2nd folder from above list.
To run the script either load it using launchctl or restart the mac.
Loading and unloading the script:
sudo launchctl load /Library/LaunchAgents/com.example.exampld.plist // for loading
sudo launchctl unload /Library/LaunchAgents/com.example.exampld.plist // for unloading
Check out apple website for keys which can be used in plist.
I hope it helps.