PDA

View Full Version : shell script after copy "cannot execute binary" error


michael.green
07-07-2008, 03:52 PM
Some time ago (http://www.shirt-pocket.com/forums/showthread.php?t=1825), you helped me to write a couple of scripts that would unmount a network share after SD had finished copying to it.

Now I'm trying the same trick at work: back up my user directory to a sparseimage on a network share. Backing up works great. But I'm running into an error with the scripts to unmount the share.

The script, "RunEjectFacStaff", waits 20 seconds and then runs an AppleScript, "ejectFacStaff", to unmount the share.

#!/bin/sh
nohup /bin/bash -c "sleep 20; osascript /Users/mjg14747/Library/Scripts/ejectFacStaff" &

The script works when run from the terminal. Check.

The permissions on the text file RunEjectFacStaff are:
-rwxr-xr-x 1 mjg14747 mjg14747 101 Jul 3 10:17 RunEjectFacStaff

They're identical with the permissions for the similar file on my home machine, where this has been working since 2006. So, check (?).

Then I ask SD to run "RunEjectFacStaff" using the third option under "After copy" in the "Advanced" tab. But, alas, here the checks stop.

| 11:49:04 AM | Error | sh: line 1: /Users/mjg14747/Library/Scripts/RunEjectFacStaff: cannot execute binary file

In short, things look the same to me but I'm getting different results. So I'm clearly missing something. If you could point me in some possible directions, that would be swell.

Thanks!

dnanian
07-07-2008, 07:19 PM
It certainly seems to think that the script isn't a text file... unless, of course, the script itself is having trouble: does it run in Terminal?

michael.green
07-07-2008, 08:39 PM
The script runs from the Terminal fine. Successfully, even.

The Finder calls it a BBEdit text file.

dnanian
07-07-2008, 10:21 PM
Try "cat"ing it into a separate file with:

cat /Users/mjg14747/Library/Scripts/RunEjectFacStaff > /Users/mjg14747/Library/Scripts/RunEjectFacStaff2
chmod +x /Users/mjg14747/Library/Scripts/RunEjectFacStaff2

Then set the 'after copy' script to /Users/mjg14747/Library/Scripts/RunEjectFacStaff2.

michael.green
07-09-2008, 02:28 PM
No luck; same error.

Error | sh: line 1: /Users/mjg14747/Library/Scripts/RunEjectFacStaff2: cannot execute binary file

dnanian
07-09-2008, 02:32 PM
I just don't know. Perhaps the other OS files are damaged somehow: an archive-and-install might help.

michael.green
07-09-2008, 02:58 PM
Oh well. Thanks!

michael.green
07-09-2008, 03:42 PM
A minute after giving up, it occurred to me to search the BBEdit lists, where I found the answer (http://www.listsearch.com/BBEdit/Thread/index.lasso?3978). Here is a diagnosis of the problem, my stab at an explanation, and the solution.

I had saved the file with the script encoded as UTF. That means the file had a BOM (Byte Order Mark). Whatever a BOM is, it comes before the #! (I surmise), meaning that the file won't be read as a binary file (I surmise). cat (I surmise) copied that mark so that didn't work either.

Saving the file with a different encoding, UTF without the BOM, solves the problem. My share on the server gracefully disappears after SD is does its thing.

dnanian
07-09-2008, 03:46 PM
Didn't you say the same file worked on your other Mac, though?

michael.green
07-09-2008, 10:18 PM
Yes, and when I look at the files on the home computer, they are UTF-no-BOM.

So how did the same file change encoding? My best guess is that I did that. I had to change the paths in the file to match those on the work computer. So I must have altered the encoding when I saved the file.

Thanks!

dnanian
07-09-2008, 10:21 PM
Glad you've got a handle on it, at least! :)