我想是这样的:条件执行和重定向在bash
maybeexec command arg1 arg2 &> /logs/log
凡maybeexec是一个bash的功能,像这样:
maybeexec() {
if ! ps ax | grep -v grep | grep "$*" > /dev/null
then
"[email protected]"
fi
}
所以基本上,它会检查是否command arg1 arg2
已经运行,并如果是这样,不会运行它。
我的问题,不过,是即使command arg1 arg2
已经运行等maybeexec
不会同时运行它,/logs/log
仍然打开重定向和将覆盖现有的/logs/log
,我不想要的。
什么是最优雅的方式来解决这个问题?如果可能的话,我愿意像现在这样继续调用maybeexec
,因为我使用它来运行许多命令,将所有输出重定向到不同的文件。
谢谢!
我切换到使用,而不是羊群,谢谢。 –