我正在努力使以下工作有效,有人可以使用bash协助我。
如果以下路径“ /opt/james/Mike${INSTANCE}/local/log/appserver.log”不存在,请尝试以下方法:“ / opt / james / Mike $ {INSTANCE} / log / appserver .log”
到目前为止,我已经尝试过:
printf "waiting for the app to start..."
{ tail -n 0 -f /opt/james/Mike${INSTANCE}/local/log/appserver.log & } | sed -n '/Server startup in/q'
{
if [ ! -f "/opt/james/Mike${INSTANCE}/local/log/appserver.log" ]; then
echo "/opt/james/Mike${INSTANCE}/log/appserver.log"
exit 0
fi
有没有更好的方法来写这个?
答案 0 :(得分:1)
我猜你想要这样的东西吗?
for p in "/opt/james/Mike${INSTANCE}/local/log" "/opt/james/Mike${INSTANCE}/log"; do
test -f "$p/appserver.log" || continue
log=$p/appserver.log
done
: maybe fail if "$log" is unset
: do things with "$log"