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