setting airport via launchd

tlarkin
Honored Contributor

I know this isn't totally Casper related but I can't seem to get this script to run for me. I am running the script manually and I get weird output errors, here is the script

#!/bin/sh

#this script will be used in conjunction with launchd to enable netowrk services #globally at start up

airportstatus=/usr/sbin/networksetup -getairportpower | grep Off -c

if [ $airportstatus -eq 1 ]

then

/usr/sbin/networksetup -setairportpower on

else echo "Airport already turned on"

fi

#set ethernet to dhcp

/usr/sbin/networksetup -setdhcp Ethernet

exit

Then here is my output:

0 Airport already turned on /Users/tlarkin/Documents/Scripts/set_netwrk_firstboot.sh: line 6: -getairportpower: command not found /Users/tlarkin/Documents/Scripts/set_netwrk_firstboot.sh: line 8: [: -eq: unary operator expected /Users/tlarkin/Documents/Scripts/set_netwrk_firstboot.sh: line 18: syntax error near unexpected token `done' /Users/tlarkin/Documents/Scripts/set_netwrk_firstboot.sh: line 18: `done' 0 Airport already turned on /Users/tlarkin/Documents/Scripts/set_netwrk_firstboot.sh: line 6: -getairportpower: command not found /Users/tlarkin/Documents/Scripts/set_netwrk_firstboot.sh: line 8: [: -eq: unary operator expected cp: /Library/Preferences/SystemConfiguration/preferences.plist.old: Permission denied

The frustrating part is that if I run the command manually, networksetup -getariportpower it freaking works....

Ideas?



Thomas Larkin
TIS Department
KCKPS USD500
tlarki at kckps.org
blackberry: 913-449-7589
office: 913-627-0351

1 REPLY 1

tlarkin
Honored Contributor

Well the problem is I needed backticks in the variable instead of single quotes. I have it working and tested it out and every time a computer is rebooted now it automatically turns on the airport and the ethernet card

I had it set to keep alive via launchd but then i realized I would probably get support calls and emails about how users can't turn their airport card off....So I changed it to only run at start up, pretty slick. If any of you are interested in doing this for your laptops drop me an email and I will give you info on how to do this.

And thanks to Miles for showing me the errors of my ways!

FYI



Thomas Larkin
TIS Department
KCKPS USD500
tlarki at kckps.org
blackberry: 913-449-7589
office: 913-627-0351