Help with a script/command to push via Casper

asditsupport
New Contributor III

I'm trying to remove a SSID from clients. I use -
networksetup -removepreferredwirelessnetwork en0 'SSID Name'
Works when I push it through ARD and/or as a command from the "Execute Command" option of Files and Processes section of a policy.
When I push it as a .sh file compiled via TextEdit, it fails. Any help is appreciated!

Error Log from Casper Remote:

Sending Wake On LAN command...
Opening SSH Connection to IP Address
Authenticating...
Successfully authenticated.
Verifying Computer's Identity...
The MAC Address has been verified.
Checking Operating System Version...
Running Mac OS X 10.8.5 (12F37)
Verifying /usr/sbin/jamf...
/usr/sbin/jamf is current (9.11)
Verifying /Library/Preferences/com.jamfsoftware.jamf.plist...
Preparing Policy...
Executing Policy 2013-10-02 at 1:05 PM | xxxx | 1 Computer...
Mounting Casper Share to /Volumes/CasperShare...
Running script Remove SSID.sh...
Script exit code: 2
Script result: /Library/Application Support/JAMF/tmp/Remove xxx.sh: line 1: {rtf1ansiansicpg1252cocoartf1187cocoasubrtf390: command not found
/Library/Application Support/JAMF/tmp/Remove SSID.sh: line 2: syntax error near unexpected token `}'
/Library/Application Support/JAMF/tmp/Remove SSID.sh: line 2: `{fonttblf0fromanfcharset0 Times-Roman;}'
Submitting log to https://casper.xxxx.xxx.xxx:8443/
Finished.

9 REPLIES 9

justinrummel
Contributor III

couple of items:

1) Was your test machine a MacBook Air or Retina? 2) What was your target machine for the script? 3) did you begin your script with #!/bin/bash

the en0 would only work for an Air or Retina as en0 is the wireless interface. All other devices en0 would be ethernet and wouldn't have an SSID option available.

Something like [code]networksetup -listnetworkserviceorder | grep ": Wi-Fi" | awk -F ": " '{print $3}' | sed 's/)//g'[/code] would find your Wi-Fi interface on a 10.8 machine and get the en# value or use system_profiler to find if the target machine is an Air or Retina the "if yes use en0 else en1".

asditsupport
New Contributor III

Hi Justin,
I'm using a MacBook Air, hence en0 for wireless
Yes, I use #! /bin/bash and also tried #! /bin/sh
The networksetup -removepreferredwirelessnetwork en0 "SSID" works when I choose to run it as a command but not as a script.

Not applicable

Looks like TextEdit is adding some of its formatting to your script which is causing it to fail based on the error message received. Typically i prefer using TextWrangler, or just vi to write a script.

asditsupport
New Contributor III

Thanks shaidar. Spot on!
I installed Text wrangler from http://download.cnet.com/TextWrangler/3000-2351_4-10220012.html
Entered the command -
networksetup -removepreferredwirelessnetwork en0 "SSID name"
Saved it with an .sh extension and pushed it through Casper Remote.

JPDyson
Valued Contributor

I think I've seen this when the script was not saved as a plain text file (TextEdit will let you save as a .sh when it's a rich text file). The main reason I don't use TextEdit, however, is that it lacks contextual formatting. I've got quite a collection of other apps that do (really, guys, I have a problem), and TextWrangler is among them. It's better than decent.

mm2270
Legendary Contributor III

I use TextWrangler for almost all my scripting needs. Its free, which is hard to beat, and has some nice features, like color coding, basic syntax checking and a good find/replace functionality. I especially like the ability to run the script from within the app and get output for testing, so I can be reasonably sure my script works before uploading it to Casper Admin. Its bigger sibling BBEdit is considered one of the better options, but I never saw the need to pay for it when TextWrangler does almost all the same things for $0.

Another option is XCode, but considering XCode is such a big application, it doesn't really make sense to me to launch it, wait for it to load, etc just to write a script. Its kind of overkill for script writing.

I will only use TextEdit if I need to whip up a script while not on my primary Mac and don't have access to other better options. Otherwise I avoid it.

scottb
Honored Contributor

TW is the best (for free) But TextEdit also works fine if you:
Change pref's to use Plain Text.
Remove .txt in file name and save as .sh.
TW will win you over though with all the good advanced features. If you need more, BBEdit.

dgreening
Valued Contributor II

BBEdit is my go-to editor for scripts. TextWrangler works as well.

calum_carey
Contributor

TW or BBEdit, or failing that nano/pico on the command line. I would never use textedit for editing scripts, have had too many problems in the past