1

I want to run a script at shutdown, and a far as I can tell I've followed the proper procedures. The script (close) is supposed to launch another script (gdrive) in a terminal which prompts me to sync my Google drive folder.

Here's what I've done:

  1. Copied files "close" and and "gdrive" into /etc/init.d and made them executable.

  2. Then I run the command update-rc.d close start 0 0 . from the command line. As expected this creates a link in /etc/rc0.d called S00close which points to the file close. Manually testing this link from the command line runs close, launches gdrive in a terminal and generally behaves as expected.

Unfortunately, nothing happens when I shutdown my machine.

Here is the code from close. In the first line I delay shutdown because I think the sync will take about 5 minutes or so:

#!/bin/sh
echo "PASSWORD" | sudo -S shutdown -c
xterm -e '/etc/init.d/gdrive'

Here is the code from gdrive (although, close doesn't run on shutdown, so I'm not sure how relevant this is):

#!/bin/sh
echo "Sync Gdrive?"
read response
if [ $response = "y" ]; then 
cd ~/Gdrive
drive push -ignore-name-clashes -quiet -ignore-conflict 
drive pull -ignore-name-clashes -quiet -ignore-conflict
echo "Drive successfully synced"
echo "PASSWORD" | sudo -S shutdown -h now
exit 1
else
echo "Ok, maybe next time"
echo "PASSWORD" | sudo -S shutdown -h now
exit 1
fi

I'm not super knowledgeable with this stuff, so any advice is appreciated. Even if someone could tell me how I can see what is happening at shutdown (what log files to look at etc.) that would be great.

terdon
  • 100,812
  • I don't understand. shutdown -c will cancel a running shutdown, not delay it by 5 minutes. You also don't need sudo, that script will be run as root. Try replacing that script with one that simply contains echo "foo" > /home/youruser/foo. Just to make sure that a simple script will be launched as expected. Check if that created the file foo in your $HOME. – terdon Jun 25 '15 at 12:43
  • Thanks for replying. I have re-evaluated my strategy a little. I've just put a button in my launcher that runs the second script. This is much simpler and accomplishes the same thing. – Billy Pilgrim Jun 25 '15 at 13:52
  • Have you tried running a script at logout instead of shutdown??? :/ – Fabby Jul 10 '15 at 19:59

1 Answers1

1

OP has solved the problem:

Thanks for replying. I have re-evaluated my strategy a little. I've just put a button in my launcher that runs the second script. This is much simpler and accomplishes the same thing.

A.B.
  • 90,397