Skip to content

Instantly share code, notes, and snippets.

@ashfame
Created November 5, 2011 23:41
Show Gist options
  • Save ashfame/1342206 to your computer and use it in GitHub Desktop.
Save ashfame/1342206 to your computer and use it in GitHub Desktop.
Shutdown linux (Ubuntu) when Dropbox completes transfer
#!/bin/bash
# By Ashfame
while true
do
# keep checking for idle dropbox status
STATUS=`dropbox status`
if [ $STATUS = 'Idle' ]; then
notify-send "System Shutdown" "System will power off now"
sleep 10
shutdown -P
exit
fi
# wait for 10 secs for the next check (iteration)
sleep 10
done
exit
@DaPutzy
Copy link

DaPutzy commented Mar 1, 2018

I used your script for my own purpose. To shutdown keepass(xc) gracefully so it'll ask if I have unsaved entries and then wait for dropbox to sync.

NOTE: On my Dropbox installation the correct state was Up to date and not Idle.

Script:

#!/bin/bash

keepass_pid=$(pidof keepassxc)

pidof_result=$?

if [ $pidof_result -eq 0 ]; then
    echo "keepassxc is running - sending graceful kill command"
    sudo kill -INT "$keepass_pid" &>/dev/null
elif [ $pidof_result -eq 1 ]; then
    echo "keepassxc is not running"
else
    echo "pidof returned unexpected exit code"
    exit 1
fi

while true; do
    keepass_pid=$(pidof keepassxc)

    pidof_result=$?

    if [ $pidof_result -eq 0 ]; then
        echo "keepassxc is still running"
    elif [ $pidof_result -eq 1 ]; then
        echo "keepassxc is not running"

        while true; do
            dropbox_status=$(dropbox status)

            if [ "$dropbox_status" = "Up to date" ]; then
                echo "dropbox up to date - will poweroff now"
                sleep 1
                poweroff
                exit 0
            else
                echo "dropbox is still syncing"
            fi

            sleep 1
        done
    else
        echo "pidof returned unexpected exit code"
        exit 1
    fi

    sleep 1
done

Example Output:

keepassxc is running - sending graceful kill command
keepassxc is still running
keepassxc is still running
keepassxc is not running
dropbox is still syncing
dropbox up to date - will poweroff now

Desktop file:

[Desktop Entry]
Type=Application
Version=1.0
Name=Delayed Shutdown
GenericName=Shutdown Delay Script
Comment=Will wait for KeepassXC and Dropbox to finish before shutting down the system
Exec=deepin-terminal -x "/XXXXXX/shutdown-after-keepassxc-sync.sh"
Categories=Others;

deepin-terminal should of course be changed to whatever your terminal is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment