網友工作中遇到的SHELL問題

來源:互聯網
上載者:User

網友的工作中SHELL問題:

問題說明:

需要截取以下命令輸出的認證編碼資訊:

#openssls_client-showcerts-connect192.168.0.111:443|sed-ne'/-BEGINCERTIFICATE-/,/-ENDCERTIFICATE-/p'(以下是認證的輸出資訊,期望:將第一個-----BEGINCERTIFICATE-----到-----ENDCERTIFICATE-----地區間的編碼儲存為一個檔案,第二個EGINCERTIFICATE-----到-----ENDCERTIFICATE區間儲存另外一個檔案,同時不能用取行的方式....)命令顯示的內容就是oldboy.log。

近期每盩厔少講4天課,時間很緊,這裡老男孩老師僅給個簡單實現,其實方法很多的,對不起夥伴們了。

簡單解答:

[root@oldboytraining~]# cat oldboy.log----BEGINCERTIFICATE-----1MIIDvDCCAqSgAwIBAgIBCTANBgkqhkiG9w0BAQUFADCBgzELMAkGA1UEBhMCQ04xEDAOBgNVBAgMB0JlaUppbmcxEDAOBgNVBAcMB0JlaUppbmcxETAPBgNVBAoMCENTREEgSUJNMRkwFwYDVQQDDBB2bTE5OC5jbi5pYm0uY29tMSIwIAYJKoZIhvcNAQkBFhNqdW5sdW9iakBjbi5pYm0uY29tMB4XDTEzMDkwMjAyNDE1NVoXDTE0MDkwMjAyNDE1NVowQjELMAkGA1UEBhMCQ04xEDAOBgNVBAgMB0JlaUppbmcxETAPBgNVBAoMCENTREEgSUJNMQ4wDAYDVQQDDAV2bTE5ODCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBANr4U+ipiJAfpmw8xTSjhsfItM9+TRWRTuLYetD3oBAb6xVOxD8T3krBxOT0Uu98+8DytfjJr1J/48BO+A1nxvrVYYWgkgnmsggju/BRt5NBORFR+DPHwjYtu2aULW7ZIy8eIS1BDb5Dk+Axywt3psE5MuI9gVtb7zC6uufQmC0HVS2yhzgke+CqPuawywvEPxAfY97k1XA43gFqWJYPs1/DY/cbVN2SgBGx3fsQAzVPQJ2c+lBkZbO79Ps75Ey2hlDfi/9/gMKTnVusvMOJTxh9WuMcCF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Bjbi5pYm0uY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA5j4hS8wJvvzdmmRNOb8VPrrwNecZU4QFbDWfkzzCDxRHoHIb8Y8OYw9EYB1wbe+CmOCwaBtIJHqhmyJ86zLYAt5hCn1rM4SxjZvEtpLoc2EL2bZor6eq2ta5kSnAOwhnioTivu7vwqpwOTDolGIsmh2qq37rm4k9+fnW8TOY/XRF5JfAIiMlhlgQqvL8//X3c4TzBse4HHtM4JCfC2Wa2mvG9IOPFT0ugMi5bFmYn6GyfY7XO9ZnG2HSat/l2jgveUiS8zOBgf6cqb1BEY2frkBsEfIcqkvpttPLNp/kJbJi8xEylmqxN2p0PuAG5oFA2ANZIPocyYM8dF8uJH1qkQIDAQABo1AwTjAdBgNVHQ4EFgQUGPqupC28Usi0Befhrx6c6OMA6R4wHwYDVR0jBBgwFoAUGPqupC28Usi0Befhrx6c6OMA6R4wDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAQEAz2yj+8ABofDAj/aYOre7fPmrB/oKjxLFc/d5V/gftbNaho1noru62d1zVcjlWNwliNEBATpA6mZFz8swxJ4AYHx1lxbAt1p98vHWmKVG8l+emMeSZ/VVmNU5HCgD+Yb1L//WO4Hjo74y3t/Q8VBa+tydvEA3VuK/CQlU4fFzKp2pQkrqYTKYejr8vBZ8hSmx0w2AsztfS8R0cIPmOP4nzyiccPxyGenGWtmJbVoW+YJR8DQfE95o4LyYYsFhpDjXPMthxyEmt5eDsVOIF4vG8qXq7r3VUpgZvt6k6GgFNuNzfAXsIQU6b1q0NNssLfLSMOIBdNmIPT4B03m4FS4PTA==-----ENDCERTIFICATE-----[root@oldboytraining~]# END="-----END CERTIFICATE-----"[root@oldboytraining~]# echo ${#END}25[root@oldboytraining~]# BEGIN="-----BEGIN CERTIFICATE-----"[root@oldboytraining~]# echo ${#BEGIN}27[root@oldboytraining~]# cat oldboy.shi=1whileread linedoif[ ${#line} -eq 27 ];then  echo "$line">>$i.logelif [ ${#line} -eq 25 ];then      echo "$line">>$i.log((i++))elseecho "$line">>$i.logfidone<oldboy.log[root@oldboytraining~]# sh oldboy.sh[root@oldboytraining~]# cat 1.log----BEGINCERTIFICATE-----1MIIDvDCCAqSgAwIBAgIBCTANBgkqhkiG9w0BAQUFADCBgzELMAkGA1UEBhMCQ04xEDAOBgNVBAgMB0JlaUppbmcxEDAOBgNVBAcMB0JlaUppbmcxETAPBgNVBAoMCENTREEgSUJNMRkwFwYDVQQDDBB2bTE5OC5jbi5pYm0uY29tMSIwIAYJKoZIhvcNAQkBFhNqdW5sdW9iakBjbi5pYm0uY29tMB4XDTEzMDkwMjAyNDE1NVoXDTE0MDkwMjAyNDE1NVowQjELMAkGA1UEBhMCQ04xEDAOBgNVBAgMB0JlaUppbmcxETAPBgNVBAoMCENTREEgSUJNMQ4wDAYDVQQDDAV2bTE5ODCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBANr4U+ipiJAfpmw8xTSjhsfItM9+TRWRTuLYetD3oBAb6xVOxD8T3krBxOT0Uu98+8DytfjJr1J/48BO+A1nxvrVYYWgkgnmsggju/BRt5NBORFR+DPHwjYtu2aULW7ZIy8eIS1BDb5Dk+Axywt3psE5MuI9gVtb7zC6uufQmC0HVS2yhzgke+CqPuawywvEPxAfY97k1XA43gFqWJYPs1/DY/cbVN2SgBGx3fsQAzVPQJ2c+lBkZbO79Ps75Ey2hlDfi/9/gMKTnVusvMOJTxh9WuMcCFQeOOTDPc7vd3Fj+XamBaOxg3yx410OMup9JQnZnLhNm3mFa7988hTSFqcCAwEAAaN7MHkwCQYDVR0TBAIwADAsBglghkgBhvhCAQ0EHxYdT3BlblNTTCBHZW5lcmF0ZWQgQ2VydGlmaWNhdGUwHQYDVR0OBBYEFFUoqZIIsnS2FheA1eKdZK4WOy3rMB8GA1UdIwQYMBaAFBj6rqQtvFLItAXn4a8enOjjAOkeMA0GCSqGSIb3DQEBBQUAA4IBAQAz7ahoRKPvtCyU8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X3c4TzBse4HHtM4JCfC2Wa2mvG9IOPFT0ugMi5bFmYn6GyfY7XO9ZnG2HSat/l2jgveUiS8zOBgf6cqb1BEY2frkBsEfIcqkvpttPLNp/kJbJi8xEylmqxN2p0PuAG5oFA2ANZIPocyYM8dF8uJH1qkQIDAQABo1AwTjAdBgNVHQ4EFgQUGPqupC28Usi0Befhrx6c6OMA6R4wHwYDVR0jBBgwFoAUGPqupC28Usi0Befhrx6c6OMA6R4wDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAQEAz2yj+8ABofDAj/aYOre7fPmrB/oKjxLFc/d5V/gftbNaho1noru62d1zVcjlWNwliNEBATpA6mZFz8swxJ4AYHx1lxbAt1p98vHWmKVG8l+emMeSZ/VVmNU5HCgD+Yb1L//WO4Hjo74y3t/Q8VBa+tydvEA3VuK/CQlU4fFzKp2pQkrqYTKYejr8vBZ8hSmx0w2AsztfS8R0cIPmOP4nzyiccPxyGenGWtmJbVoW+YJR8DQfE95o4LyYYsFhpDjXPMthxyEmt5eDsVOIF4vG8qXq7r3VUpgZvt6k6GgFNuNzfAXsIQU6b1q0NNssLfLSMOIBdNmIPT4B03m4FS4PTA==-----ENDCERTIFICATE-----

查看本欄目更多精彩內容:http://www.bianceng.cnhttp://www.bianceng.cn/OS/Linux/

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.