I’ve written a script that loads multiple instances of Dropbox (below). It works fine when I run it from the command line.
I noticed that when I leave the computer and it locks the screen so I have to log on again that the dropbox instances also drop from memory so I have to run the script again when I log in.
So, to save having to remember that I put the script on a personal (not system) cronjob. This works in the sense that I can see that it keeps the instances in memory. However, once the cronjob loads this into memory the instances no longer show in system tray. I guess this could be because it’s loading the instances while on the log on screen which means there is no system tray showing, I guess.
In any case is there a simple solution… maybe there’s some sort of check you can do to determine that someone is logged in before continuing through a script? Or maybe I just need to add an env variable to the script?
Anyway, if someone has a solution I would appreciate it.
#!/bin/sh
HOME_DIR=$HOME
DROPBOXES=("$HOME/.dropboxes/personal" "$HOME/.dropboxes/work")
function start_dropbox() {
HOME=$HOME_DIR
local flag
local home_dir
local silent=0
local OPTIND;
local verbose=0
local wait=0
while getopts p:svw opt; do
case $opt in
p) home_dir="$(echo $OPTARG | sed 's:/*$::')/" ;;
s) silent=1 ;;
v) verbose=1 ;;
w) wait=1 ;;
*) ;;
esac
done
shift $((OPTIND-1))
# Test if the process is already running
local pid=$(ps aux|grep "${home_dir}.dropbox-dist"|grep -v 'grep'|tr -s ' '| cut -d' ' -f 2)
if -n "$pid" ]
then
if $silent -eq 0 ]; then
echo "Process already running with home dir. of: $home_dir"
fi
return 8 # Process already running
fi
# Create home directory if it doesn't exist
if ! -e "$home_dir" ]
then
if mkdir -p "$home_dir";
then
if $silent -eq 0 ]; then
echo "Created directory: $home_dir"
fi
else
if $silent -eq 0 ]; then
echo "Failed to create directory: $home_dir"
fi
return 9 # Failed
fi
fi
# Set up so works with GUI from command line
xauthority="${home_dir}.Xauthority"
if ! -e "$xauthority" ]
then
ln -s "$HOME/.Xauthority" "$xauthority"
fi
HOME="$home_dir"
# Start the dropbox daemon
if $verbose -gt 0 ]]; then
if $silent -eq 0 ]; then
echo '~/.dropbox-dist/dropboxd & '$home_dir
fi
fi
~/.dropbox-dist/dropboxd &
if $wait -eq 0 ]]; then
sleep 2 # Give each instance time to startup completely before starting another one
else
if $silent -eq 0 ]; then
read -n 1 -s -p 'Press any key to continue.'
echo
fi
fi
}
function start_dropboxes() {
local dropbox
for dropbox in "${DROPBOXES@]}"
do
start_dropbox $@ -p "$dropbox"
done
}
#
# For testing & setup we can choose just one to startup
#
while getopts f:swv opt; do
case $opt in
f) start_dropbox -p "${DROPBOXES$OPTARG]}" # NOTE: bash array indexes start at 0.
exit ;;
*) ;;
esac
done
OPTIND=1
start_dropboxes $@