1
我想截断一个shell脚本的输出,只打印匹配字符串/正则表达式和EOF的最后一行之间的部分。truncate shell命令输出从最后一行匹配一个字符串,直到EOF
如letsencrypt certbot renew --post-hook "service apache2 reload; service nginx reload"
运行时,我得到这样的
...
http-01 challenge for domain1.tld
Waiting for verification...
Cleaning up challenges
-------------------------------------------------------------------------------
new certificate deployed without reload, fullchain is
/etc/letsencrypt/live/domain1.tld/fullchain.pem
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
Processing /etc/letsencrypt/renewal/domain2.tld
-------------------------------------------------------------------------------
Renewing an existing certificate
Performing the following challenges:
http-01 challenge for domain.tld
http-01 challenge for www.domain2.tld
Waiting for verification...
Cleaning up challenges
-------------------------------------------------------------------------------
new certificate deployed without reload, fullchain is
/etc/letsencrypt/live/domain2.tld/fullchain.pem
-------------------------------------------------------------------------------
** DRY RUN: simulating 'certbot renew' close to cert expiry
** (The test certificates below have not been saved.)
Congratulations, all renewals succeeded. The following certs have been renewed:
/etc/letsencrypt/live/domain1.tld/fullchain.pem (success)
/etc/letsencrypt/live/domain2.tld/fullchain.pem (success)
/etc/letsencrypt/live/domain3.tld/fullchain.pem (success)
/etc/letsencrypt/live/domain4.tld/fullchain.pem (success)
** DRY RUN: simulating 'certbot renew' close to cert expiry
** (The test certificates above have not been saved.)
Running post-hook command: service apache2 reload; service nginx reload
Output from service:
* Reloading web server apache2
*
* Reloading nginx configuration nginx
...done.
现在我想拥有的是最后-------
行之后的一切,所以期望的结果将是
** DRY RUN: simulating 'certbot renew' close to cert expiry
** (The test certificates below have not been saved.)
Congratulations, all renewals succeeded. The following certs have been renewed:
/etc/letsencrypt/live/domain1.tld/fullchain.pem (success)
/etc/letsencrypt/live/domain2.tld/fullchain.pem (success)
/etc/letsencrypt/live/domain3.tld/fullchain.pem (success)
/etc/letsencrypt/live/domain4.tld/fullchain.pem (success)
** DRY RUN: simulating 'certbot renew' close to cert expiry
** (The test certificates above have not been saved.)
Running post-hook command: service apache2 reload; service nginx reload
Output from service:
* Reloading web server apache2
*
* Reloading nginx configuration nginx
...done.
我想过一些tail -n 15
命令,但我不想每次添加新域时调整我的脚本。
感谢您的帮助!
编辑:在此期间,我发现我自己的一个解决方案,它是不是像你一样@ anubhava的
cnt1=`grep -n "\----" certbot.log | tail -n1 | awk -F : '{ print $1 }'`
cnt2=`wc -l certbot.log | awk '{ print $1 }'`
cnt3=$((cnt2-cnt1))
tail -n $cnt3 certbot.log
BTW您的解决方案只适用于'GAWK '不与'mawk' – simne7
我已经在BSX上测试过它awk,并且它在那里工作得很好。可能'mawk'不喜欢'/^- {6} /',你可以在这里使用:'/ ------ /'。 – anubhava
jep!而已。尼斯。谢谢 :) – simne7