2

Here is my question. Since there is a problem for my dropbox folder to do automatics sync. I have to add " ~/.dropbox-dist/dropboxd &" in my .bashrc. So whenever I open my terminal, it will automatically start synchronizing. The problem arise when I want to have another tab in my terminal. I am receiving following warning that "Another instance of Dropbox (8664) is running! ". Although it does not affect my dropbox, it is quite annoying. I searched but unfortunately I could not find the solution on the web. So any help will be appreciated in advance.

Thanks

H'H
  • 1,638
  • 1
  • 15
  • 39
  • possible duplicate of [Linux/Unix command to determine if process is running?](http://stackoverflow.com/questions/9117507/linux-unix-command-to-determine-if-process-is-running) – fredtantini Oct 21 '14 at 08:00
  • 2
    This does not sound like a command that should be in `.bashrc` but running at boottime instead. Did you try that? – Tim Zimmermann Oct 21 '14 at 08:01
  • 2
    Use `ps` (with `-C`) to check if the process is running and launch only if not. Alternatively, simply launch and redirect the error messages to `/dev/null` if you don't want to see them. – Noufal Ibrahim Oct 21 '14 at 08:02
  • @TimZimmermann Thanks, How can I run it at boottime, The point is that I don't have access as root. – H'H Oct 21 '14 at 08:03
  • @NoufalIbrahim like "ps -C ~/.dropbox-dist/dropboxd &" ?? – H'H Oct 21 '14 at 08:08
  • Check the answer that @fredtantini has linked to. It has some code you might be able to repurpose. – Noufal Ibrahim Oct 21 '14 at 08:11
  • 1
    You can create a cronjob that is run on reboot, assuming that you are on a Linux that supports it. Try running `crontab -e` and add the line `@boot /home/user/.dropbox-dist/dropboxd`. Note the absolute path instead of `~`, so you have to substitute your username. – Tim Zimmermann Oct 21 '14 at 08:13
  • @TimZimmermann I receive following: crontab: installing new crontab "/tmp/crontab.QcfA8j":1: bad time specifier errors in crontab file, can't install. Do you want to retry the same edit? – H'H Oct 21 '14 at 08:18
  • Okay, then try `@reboot` instead of `@boot`. If that does not work, please tell us on which Linux (Distro) you are working on. – Tim Zimmermann Oct 21 '14 at 08:24
  • @TimZimmermann reboot works fine, thanks. Please write your answer in the answer section so i can choose it as the best answer. – H'H Oct 21 '14 at 08:28

3 Answers3

1

add it to yout .bashrc

ps cax | grep dropbox > /dev/null
if [ $? -eq 0 ]; then
  echo "Process is running."
else
  ~/.dropbox-dist/dropboxd &
  echo "Process is not running."
fi
user2090491
  • 568
  • 2
  • 5
  • 15
  • 1
    This will incorrectly mark the process as already running if another user on the system is running it. Also, the `grep` will match process names which contain `dropbox` as a substring, not just exact matches (though that could be fixed with a tighter regex and/or additional options). – tripleee Oct 21 '14 at 08:32
  • And of course, anything that looks like `pipeline; if [ $0 -eq 0 ]; then` is more idiomatically written `if pipeline; then` – tripleee Jul 02 '16 at 05:56
1

Add a guard to your .bashrc to only run it if it isn't running already.

pidof -c dropboxd || ./~dropbox-dist/dropboxd &

(This is assuming you have pidof but that should be trivially true on most modern Linux distros.)

tripleee
  • 175,061
  • 34
  • 275
  • 318
  • You might want to specify the full path in the argument to `pidof` if there could be multiple users running the same command. There unfortunately doesn't seem to be an option to only examine processes of your own; but most likely only you would run a binary from your home directory tree. – tripleee Jul 02 '16 at 06:04
0

Building from @tripleee's answer, the following works with the official Dropbox Python control script (eg for headless Digital Ocean boxes) and doesn't output the pid on screen:

pidof -c dropbox > /dev/null || ~/bin/dropbox.py start # start dropbox

It assumes you have dropbox.py stored in ~/bin and marked executable.

turnspike
  • 1
  • 1
  • 2
  • It's not entirely clear where you're getting the python script from - is [this](https://www.dropbox.com/download?dl=packages/dropbox.py) the one you mean? – Simon MᶜKenzie Feb 16 '17 at 04:17
  • 1
    @SimonMᶜKenzie yes the offical dropbox.py, it is needed for non-graphical Linux systems. I have now edited to clarify. – turnspike Feb 16 '17 at 10:23