检查bashrc中是否正在运行命令

时间:2021-08-14 07:37:38

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.

这是我的问题。因为dropbox文件夹有一个自动同步的问题。我必须加上“~/”。在我的。bashrc中。所以每当我打开我的终端,它就会自动开始同步。当我想要在我的终端上有另一个标签时,问题就出现了。我收到以下警告:“Dropbox(8664)的另一个实例正在运行!””。虽然它不影响我的dropbox,但它相当烦人。我搜索了,但不幸的是我在网上找不到解决方案。因此,任何帮助都将得到事先的感谢。

Thanks

谢谢

3 个解决方案

#1


1  

add it to yout .bashrc

添加到。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

#2


1  

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

向.bashrc添加一个保护,以仅在它尚未运行时运行它。

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

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

(这是假设您有pidof,但在大多数现代Linux发行版上,这应该是非常正确的。)

#3


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:

基于@tripleee的回答,以下是官方Dropbox Python控制脚本(如无头数字海洋盒子),并没有在屏幕上输出pid:

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

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

它假设你有dropbox。py存储在~/bin中并标记为可执行文件。

#1


1  

add it to yout .bashrc

添加到。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

#2


1  

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

向.bashrc添加一个保护,以仅在它尚未运行时运行它。

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

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

(这是假设您有pidof,但在大多数现代Linux发行版上,这应该是非常正确的。)

#3


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:

基于@tripleee的回答,以下是官方Dropbox Python控制脚本(如无头数字海洋盒子),并没有在屏幕上输出pid:

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

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

它假设你有dropbox。py存储在~/bin中并标记为可执行文件。