Skip to main content
Question

Help with a script/command to push via Casper


Forum|alt.badge.img+7

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

Forum|alt.badge.img+13
  • Contributor
  • 159 replies
  • October 2, 2013

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".


Forum|alt.badge.img+7
  • Author
  • Contributor
  • 36 replies
  • October 2, 2013

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.


  • 0 replies
  • October 2, 2013

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.


Forum|alt.badge.img+7
  • Author
  • Contributor
  • 36 replies
  • October 2, 2013

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.


Forum|alt.badge.img+13
  • Valued Contributor
  • 478 replies
  • October 2, 2013

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.


Forum|alt.badge.img+16
  • Legendary Contributor
  • 7880 replies
  • October 2, 2013

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
Forum|alt.badge.img+18
  • Valued Contributor
  • 1285 replies
  • October 2, 2013

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.


Forum|alt.badge.img+18
  • Honored Contributor
  • 645 replies
  • October 2, 2013

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


Forum|alt.badge.img+7
  • Contributor
  • 58 replies
  • October 2, 2013

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


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings