1

Regarding stackexchange post how to get shell scripts to run at startup on Yosemite

The offering here is interesting but all I want to do is set the ip address of one of the ethernet interfaces, en0 with ifconfig. I don't want to launch a deamon.

the command to run is just:

ifconfig en0  inet 192.168.1.23 netmask 255.255.255.0 

Of course the interface drivers have to be launched and the interfaces available for configuration. This has to be run by root, other wise it has to be prefaced with sudo, which has to have the credentials provided.

I have the root account activated on this system and am comfortable with and know most of the hazards.

But I don't want to do this manually every time the machine is booted or restarted.

Perhaps someone from Apple has a reference to a patch or info on why the network preference operations for manual configuration of interfaces will not set them on mine.

I have been buying and using Macs since the late 1990's. This is one of only two out of nearly a dozen Macs I have owned that is not newly purchased from a reputable dealer.

Apache server will also not launch with the web sharing option.

Perhaps the machine with the installation is too old? It is

Note: I BOUGHT THIS MACHINE USED FOR CASH
 Model Name:    MacBook Pro
 Model Identifier:  MacBookPro5,1
 Processor Name:    Intel Core 2 Duo
 Processor Speed:   2.4 GHz
 Number of Processors:  1
 Total Number of Cores: 2
 L2 Cache:  3 MB
 Memory:    4 GB
 Bus Speed: 1.07 GHz
 Boot ROM Version:  MBP51.007E.B06
 SMC Version (system):  1.33f8
 <sn deleted for this post>
  Hardware UUID:    63410FEB-9CFF-5C8C-A692-8733BBEE36C5
 Sudden Motion Sensor:
 State: Enabled

This does not tell me its actuall manufacture date.

Thank you for time and attention

Jeff

  • Is the script you put in /System/Library/StartupItems/ executable and owned by root? – tron_jones Nov 15 '14 at 1:53
  • MBP 5,1 is a Late 2008 model. – tubedogg Nov 15 '14 at 4:13
  • That said the age of the machine is irrelevant to what you are trying to do. It's the OS that would determine if something will work or not, and running shell scripts at login should not be an issue in Yosemite. – tubedogg Nov 15 '14 at 4:15
  • @tron_jones: Yes the script is executable and owned by root because it configures a network interface. I set the executable bit on it, I believe that's what you do, – JeffK Nov 16 '14 at 1:48
  • Why not just set it in the Network pane of System Preferences, like normal? – Gordon Davisson Nov 16 '14 at 3:24
3

You could save your script whatever you want and call it from a .plist file saved on /Library/LaunchAgents/ to be launched at startup.

Let me explain how to do it with an example.

  • Create you script and save it on /Users/username/setip.sh.
  • Create a new file called com.username.setip.plist in /Library/LaunchAgents/. This file must have the following format:
<?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.username.setip</string>

  <key>ProgramArguments</key>
  <array>
    <string>/Users/username/setip.sh</string>
  </array>

  <key>Nice</key>
  <integer>1</integer>

  <key>StartInterval</key>
  <integer>60</integer>

  <key>RunAtLoad</key>
  <true/>

  <key>StandardErrorPath</key>
  <string>/tmp/com.username.setip.err</string>

  <key>StandardOutPath</key>
  <string>/tmp/com.username.setip.out</string>
</dict>
</plist>

The file is pretty self-explanatory. It will launch the command /Users/username/setip.sh every 60 seconds, will be launched at load, will save errors on /tmp/com.username.setip.err and logs on /tmp/com.username.setip.out.

Restart, and the script will be executed.

  • If the script is to run as root at startup, this needs to be put in /Library/LaunchDaemons. LaunchAgents run when a user logs in, as that user. – Gordon Davisson Nov 16 '14 at 3:23
  • So where does the "every 60 seconds" come from? – mkataja Mar 18 '15 at 11:17
  • Sorry, forget to include a couple of lines. The "every 60 secons" comes from the line with StartInterval and the following value is the time in seconds. – jherran Mar 19 '15 at 7:21
  • it doesnt work ! – saruftw May 7 '15 at 20:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .