【发布时间】:2013-07-16 16:43:14
【问题描述】:
当我在 Ubuntu 上单击 NetBeans 或 DropBox 等程序时,有没有办法执行 bash 脚本 并在退出时执行一个 bash 脚本
我的想法是在 cronjob @reboot 上创建 bash 脚本,每秒检查一下程序是否存在于当前进程中
#!/bin/bash
NameOfprogram="NetBeans"
while [[ true ]]; do
countOfprocess=$(ps -ef |grep $NameOfprogram | wc -l)
if [[ $countOfprocess -gt 1 ]]; then
#execute bash
fi
sleep 1
done
但我认为这个想法不是最好的,有没有更好的方法来实现它?
【问题讨论】:
-
这听起来像是一个简单问题的错误解决方案......
-
while [[ true ]]检查字符串“true”是否为空。它适用于无限循环,但对[[的工作方式有些困惑。while [[ false ]]会有相同的结果。while true执行内置的true。 -
@Ignacio Vazquez-Abrams 有更好的解决方案吗??
-
不知道实际问题是什么。
-
如果您说这是一个糟糕的解决方案,那么最好的解决方案是什么?