简体   繁体   English

我怎样才能使这个bash脚本成为一个单行?

[英]How can I make this bash script into an one-liner?

I need a more compact, preferably an one-liner, for the following bash script: 对于以下bash脚本,我需要一种更紧凑的(最好是单线):

#/bin/sh
service openstack-keystone status > /dev/null
service_rc=$?
keystone token-get 2>&1 | grep "^Authentication Failed" > /dev/null
keystone_rc=$?
if [ $service_rc != 0 -o $keystone_rc == 0 ]
then
        echo "need to restart"
else
        echo "ok"
fi

I eventually have to get this logic into a puppet service where the standard status check is not enough. 我最终不得不将这种逻辑引入到标准状态检查还不够的木偶服务中。

Updated. 更新。 Sorry for not be more clear in my initial question and thanks to you that have commented and answered. 抱歉,我最初的问题还不清楚,谢谢您的评论和回答。 :) :)

You can use: 您可以使用:

service blah status > /dev/null &&
    keystone token-get 2>&1 | grep -q "^Authentication Failed" &&
    echo "ok" || echo "need to restart"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM