View Full Version : Script Help

01-07-2007, 11:03 PM
:confused: I would like SuperDuper to run a script that reboots my computer from the same startup disk that it is currently running from after completion.

I know nothing about shell scripting.



(My attempts to run a compile applescript have failed due to permissions problems, although I thought the permissions were fine.) The log reads: Error | sh: line 1: /Users/Shared/Restart.scpt: Permission denied

01-07-2007, 11:13 PM
Any particular reason why you want to do that, Scott?

01-07-2007, 11:20 PM

This is a shared computer at our church. It boots itself every Sunday AM very early. SD runs as 'root' a few minutes after boot up. I could shut down the computer, but it is more convenient to have it up and running for either remote access early, or for the tech crew who comes in a couple hours later.

However, when using SD like this, the system administrator is logged in despite the MacOSX login window being visible. This could present problems.

So, if the computer where to reboot from the same startup disk after completion, then all would be OK.

01-07-2007, 11:23 PM
OK. Try putting this in a text file:

shutdown -r +1

Once that's saved, then -- in Terminal, run:

chmod +x the-file-you-saved

Then, set that as the "after copy" script, and you should be all set: it'll shut down one minute after the copy is complete.

01-07-2007, 11:32 PM
Actually, I want the computer to reboot, not shutdown. For a shutdown, couldn't I just do that via the SD interface itself?

Also, I tried something similar with terminal but got myself confused (novice here.) I saved code in TextEdit, then opened Terminal and did the chmod +x, hit return, and then dragged the saved file into terminal to set the path.

However, does this do something to the text file itself? Or, do I have to save the terminal as something?

Sorry for being so numb.


01-07-2007, 11:48 PM
Well, I tried to make a shell script, but I still really don't know what I am doing. I get the following error (same error when I tried to get SD to run a simple compiled applescript)

......COMMAND => Invoking After Copy shell script: /private/var/root/Desktop/Restart Shell Text.rtf
| 10:46:11 PM | Error | sh: line 1: /private/var/root/Desktop/Restart Shell Text.rtf: Permission denied

01-08-2007, 07:49 AM
Two things. "shutdown -r" does a restart, not a shutdown.

Second, you need to make a plain text file, not an RTF file. And, it looks like you didn't make it executable with the 2nd command provided.

01-08-2007, 09:12 AM
Again, I apologize for being such a novice, but I really don't know how to make/save an executable.

I rewrote the code and saved as plain text. I opened terminal and typed the code you supplied. I opened terminal and did the chmod command as supplied.

But what is next? Nothing happens. I can save the text file, but it appears to be nothing but text. Do I save a terminal document instead? What kind? etc.?

Sorry, but I guess I need hand holding and precise click by click instructions.

Here is the log from my latest try.

..ACTION: Running shell script restartshellscript.txt
| 08:20:12 AM | Info | ......COMMAND => Invoking After Copy shell script: /private/var/root/Desktop/restartshellscript.txt
| 08:20:12 AM | Info | Copy complete.
However, no restart occured. Waited 3-4 minutes, nothing.

Thanks again,


01-08-2007, 09:30 AM
Try running your restartshellscript.txt from the shell itself. The command would be:


(Followed by Return, of course.)

01-12-2007, 11:09 PM
Tried it, nothing happens.


01-12-2007, 11:12 PM
Something must be wrong with what you put in the script, then. If you type:

shutdown -r now

in Terminal, does your system reboot?

01-12-2007, 11:20 PM
Yup, reboots with shutdown -r now in terminal.

the code in the restart script is:

shutdown -r +1

01-12-2007, 11:21 PM
OK -- let's try that command, too, then, in Terminal:

shutdown -r +1

It should restart after a minute.

01-12-2007, 11:24 PM
OK, I did and it did restart in 1 minute. I believe that my txt file had 2 spaces between the -r and the +1. When I made certain that there was a single space and typed it directly into terminal, it did restart in 1 minute.

So I modified restartshellscript.txt in a text editor to be sure that there was no double space. However, when I try /private/var/root/Desktop/restartshellscript.txt ; still nothing happens.

01-12-2007, 11:33 PM
And when you type:

cat /private/var/root/Desktop/restartshellscript.txt

it prints to the Terminal and looks normal?

If you do a:

ls -l /private/var/root/Destktop/restartshellscript.txt

what do you get? (Paste it in here.)

01-12-2007, 11:38 PM
Here is what I have in a terminal window.

Last login: Fri Jan 12 22:31:33 on ttyp1
Welcome to Darwin!
SBC-Sanctuary:~ root# cat /private/var/root/Desktop/restartshellscript.txt
SBC-Sanctuary:~ root# cat /private/var/root/Desktop/restartshellscript.txt
SBC-Sanctuary:~ root# ls -l /private/var/root/Destktop/restartshellscript.txt
ls: /private/var/root/Destktop/restartshellscript.txt: No such file or directory
SBC-Sanctuary:~ root#

01-13-2007, 10:11 AM
Well... that certainly implies that the file isn't where you indicated it was, isn't named that, etc... do an

ls -l ~/Desktop

to see what it's really called.

01-15-2007, 10:51 PM
Last login: Mon Jan 15 21:46:47 on console
Welcome to Darwin!
SBC-Sanctuary:~ root# ls -l ~/Desktop
total 2920
-rw------- 1 root wheel 6148 Jan 12 22:32 .DS_Store
-rw------- 1 root wheel 0 Nov 3 2005 .localized
-rwxrwxrwx 1 root wheel 1481534 Mar 18 2006 Take Control of Making Music with GarageBand (3.0).pdf
-rwxr-xr-x 1 root wheel 25 Jan 12 22:21 restartshellscript.txt
SBC-Sanctuary:~ root#

01-15-2007, 10:53 PM
ok, so:

cat ~/Desktop/restartshellscript.txt

should print it out...

01-15-2007, 11:14 PM
I have no printer connected to this printer, so after
cat ~/Desktop/restartshellscript.txt and 'return', nothing seems to happen.

01-15-2007, 11:18 PM
No printer needed. If nothing happens, the file is empty.

Let's create this file in Terminal. Note: you cannot make any typing errors here. Type:

cat >~/Desktop/restart.shell
shutdown -r +1
^D (that is, Control-d, don't type ^D or this text :))


chmod +x ~/Desktop/restart.shell

Ok. Now:

cat ~/Desktop/restart.shell

And that should show the text you typed. Finally:


should restart you.

01-18-2007, 01:25 AM
Progress has been made, thank you.

Doing what you wrote above I was able to get a shell script to restart the Mac. I then ran SuperDuper with the shell script being executed after completion of the backup script.

Interestingly, the SD window last step said 'script failed to execute' or some similar error message. However, after one minute the machine rebooted, so obviously it did run indeed. Below is that portion of the SD log.

12:18:42 AM | Info | ...ACTION: Running shell script restart.shell
| 12:18:42 AM | Info | ......COMMAND => Invoking After Copy shell script: /private/var/root/Desktop/restart.shell
| 12:18:42 AM | Error | shutdown: [pid 259]

Anyway, I think that what I wish to accomplish will now work, but am curious about the error.

Thank you, Scott

01-18-2007, 09:16 AM
I think this is because we got a signal that the system is shutting down. There are ways to fix this, e.g:

nohup /bin/bash -c "sleep 10; shutdown -r +10" &

01-18-2007, 09:01 PM
Well, it sounds as if I would have to start over creating the shell script and other than following your recipe, I really don't know what I am doing. However, is there any harm in leaving it the way it is with the error?

01-18-2007, 09:02 PM
Not really...

01-18-2007, 09:27 PM
Thank you for your help.

In summary, if I were to re-create the shell script via terminal I would then use the code
nohup /bin/bash -c "sleep 10; shutdown -r +10" &
instead of
cat >~/Desktop/restart.shell
shutdown -r +1
Is this correct?

01-18-2007, 09:31 PM
That's rightish (the code goes in the pace of the

shutdown -r +1

of course, the other parts actually create the file with the code in it).

01-21-2007, 08:27 AM
Well, maybe I spoke to soon. There is another level of complexity here, and got the following error on an autoexecution this AM.

| 05:09:32 AM | Info | ...ACTION: Running shell script restartshellscript.txt
| 05:09:32 AM | Info | ......COMMAND => Invoking After Copy shell script: /private/var/root/Desktop/restartshellscript.txt
| 05:09:32 AM | Error | sh: line 1: /private/var/root/Desktop/restartshellscript.txt: No such file or directory

This machine boots up automatically at 4:55AM Sunday mornings to the log-in screen. Because the root account is running SD, the scheduled execution of the backup did run and SD appears behind the log-in window. However, the restart shell script apparantly could not be found and gave the above error.

Would it make any difference if the path to the shell script were in the Shared users directory? Or is this just going to be a problem because of the log-in window screen being where the computer is at? Or would the newly suggested code be better?

TIA, Scott

01-21-2007, 08:26 PM
You can put it anywhere you want (as long as it's readable by root) -- it just has to be in that location, and it doesn't look like it's where you've indicated it is...