{"id":1560,"date":"2024-10-19T11:05:28","date_gmt":"2024-10-19T03:05:28","guid":{"rendered":"http:\/\/blue.yn.cn\/?p=1560"},"modified":"2024-12-21T11:44:07","modified_gmt":"2024-12-21T03:44:07","slug":"%e5%ae%9a%e6%97%b6%e5%a4%87%e4%bb%bd%e7%bd%91%e7%bb%9c%e8%ae%be%e5%a4%87%e9%85%8d%e7%bd%ae%e6%96%87%e4%bb%b6","status":"publish","type":"post","link":"http:\/\/blue.yn.cn\/?p=1560","title":{"rendered":"\u5b9a\u65f6\u5907\u4efd\u7f51\u7edc\u8bbe\u5907\u914d\u7f6e\u6587\u4ef6"},"content":{"rendered":"<h4>\u7f16\u8f91\u7f51\u7edc\u8bbe\u5907ip\u5730\u5740\u548c\u540d\u79f0<\/h4>\n<pre><code class=\"language-bash\">cat \/root\/net_bak_cfg\/net_ip_list\n192.168.1.2 msr3600\n192.168.1.3 s5500\n192.168.1.4 fw1000<\/code><\/pre>\n<h4>zabbix server\u7f16\u5199shell\u811a\u672c<\/h4>\n<pre><code class=\"language-bash\">cat \/root\/net_bak_cfg\/netbak_cfg.sh\n#!\/bin\/bash\n\nip_list=\/root\/net_bak_cfg\/net_ip_list\n\nwhile read line\ndo\n        host_ip=$(echo $line | awk &#039;{print $1}&#039;)\n        host_name=$(echo $line | awk &#039;{print $2}&#039;)\n        # \u7f51\u7edc\u8bbe\u5907\u914d\u7f6e\u6587\u4ef6\u7684\u8def\u5f84\n        src_file=&quot;flash:\/startup.cfg&quot;\n        dest_file=\/var\/log\/cfg_log\/$(date &quot;+%Y%m%d&quot;)\/\n        mkdir -p ${dest_file}${host_name}\n        expect -f \/root\/net_bak_cfg\/net_bak.expect &quot;$host_ip&quot; &quot;$host_name&quot; &quot;$src_file&quot; &quot;$dest_file&quot;\ndone &lt; ${ip_list}<\/code><\/pre>\n<ul>\n<li><code>expect<\/code>\u6587\u4ef6<\/li>\n<\/ul>\n<pre><code class=\"language-bash\">cat \/root\/net_bak_cfg\/net_bak.expect\n#!\/usr\/bin\/expect\n\n# \u8bbe\u5907\u5bc6\u7801\u81ea\u52a8\u8f93\u5165\nset host_ip [ lindex $argv 0 ]\nset host_name [ lindex $argv 1 ]\nset src_file [ lindex $argv 2 ]\nset dest_file [ lindex $argv 3 ]\n\nspawn scp ylzw@${host_ip}:${src_file} ${dest_file}${host_name}\nexpect {\n    &quot;(yes\/no)?&quot;\n            {\n                send &quot;yes\\n&quot;\n                expect &quot;password:&quot; {send &quot;xxx\\n&quot;}\n            }\n    &quot;password:&quot;\n            {\n                send &quot;xxx\\n&quot;\n            }\n}\nexpect &quot;100%&quot;\nexpect eof<\/code><\/pre>\n<h4>zabbix server\u5b9a\u65f6\u4efb\u52a1<\/h4>\n<pre><code class=\"language-bash\">#\u6bcf\u54685\u665a\u4e0a10\u70b9\u6267\u884c\u5907\u4efdmsr3600\u914d\u7f6e\u6587\u4ef6\u64cd\u4f5c\uff1bby:yujing 2024\/10\/18\n00 22 * * 5 bash -x \/root\/net_bak_cfg\/netbak_cfg.sh &amp;&gt; \/tmp\/cfg.log<\/code><\/pre>\n<h4>\u5f00\u542fscp\u670d\u52a1<\/h4>\n<ul>\n<li>\u534e\u4e09\u4ea4\u6362\u673a\u8981\u5f00\u542f<code>scp server enable<\/code>\u540e\u624d\u80fd\u8fdc\u7a0b\u62f7\u8d1d\u914d\u7f6e\u6587\u4ef6\uff0c\u4e0b\u9762\u662f\u6279\u91cf\u6253\u5f00<code>scp<\/code>\u670d\u52a1\u7684\u811a\u672c<\/li>\n<\/ul>\n<pre><code class=\"language-bash\">cat scp_enable_unreachable.sh\n#!\/usr\/bin\/bash\n# \u53d6\u4e4b\u524dping\u4e0d\u901a\u7684\u4ea4\u6362\u673a\u4fe1\u606f\uff0c\u5b9a\u65f6\u6267\u884c\u811a\u672cping\u6d4b\u8bd5\uff0c\u5982\u679c\u80fdping\u901a\uff0c\u6253\u5f00scp\u670d\u52a1\u3002\u5168\u90e8\u6253\u5f00\u540e\uff0c\u53d1\u90ae\u4ef6\u63d0\u9192\nip_list=\/root\/kaoshizw\/S5120ip_unreachable\nif [ -s $ip_list ];then\n        while read line\n        do\n                host_ip=$(echo $line | awk &#039;{print $2}&#039;)\n                host_name=$(echo $line | awk &#039;{print $1}&#039;)\n\n                ping -W 1 -c 1 $host_ip &amp;&gt; \/dev\/null\n\n                if [ $? -eq 0 ];then\n                        echo $host_ip $host_name\n                        expect -f \/root\/kaoshizw\/scp_enable.expect &quot;$host_ip&quot;\n                        sed  -i &quot;\/$host_ip\/d&quot; $ip_list\n                fi\n        done &lt; ${ip_list}\nelse\n        bash \/opt\/send_mail2.sh &amp;&gt; \/dev\/null\nfi\n\ncat scp_enable.expect\n#!\/usr\/bin\/expect\n# \u8bbe\u5907\u5bc6\u7801\u81ea\u52a8\u8f93\u5165\nset host_ip [ lindex $argv 0 ]\nspawn ssh zsksy@${host_ip}\nexpect {\n    &quot;(yes\/no)?&quot;\n            {\n                send &quot;yes\\n&quot;\n                expect &quot;password:&quot; {send &quot;xxx\\n&quot;}\n            }\n    &quot;password:&quot;\n            {\n                send &quot;xxx\\n&quot;\n            }\n}\nexpect &quot;&gt;&quot;\nsend &quot;sys\\n&quot;\nexpect &quot;]&quot;\nsend &quot;scp server enable\\n&quot;\nexpect &quot;]&quot;\nsend &quot;quit\\n&quot;\nexpect &quot;&gt;&quot;\nsend &quot;save\\n&quot;\nexpect &quot;sure&quot;\nsend &quot;Y\\n&quot;\nexpect &quot;enter&quot;\nsend &quot;\\n&quot;\nexpect &quot;overwrite&quot;\nsend &quot;Y\\n&quot;\nexpect &quot;wait&quot;\nexpect eof<\/code><\/pre>\n<ul>\n<li>\u5b9a\u65f6\u4efb\u52a1\uff0c\u6bcf\u96941\u5929\u768419\u70b9\u6d4b\u8bd5\u4e4b\u524dping\u4e0d\u901a\u7684\u4ea4\u6362\u673a\uff0c\u5982\u679cping\u901a\uff0c\u5c31\u6253\u5f00scp\uff0c\u5168\u90e8ping\u901a\u540e\uff0c\u53d1\u90ae\u4ef6<br \/>\n<code>0 19 *\/1 * * bash -x \/root\/kaoshizw\/scp_enable_unreachable.sh &amp;&gt; \/tmp\/cfg.log<\/code><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u7f16\u8f91\u7f51\u7edc\u8bbe\u5907ip\u5730\u5740\u548c\u540d\u79f0 cat \/root\/net_bak_cfg\/net_ip_list 192.168&#8230; &raquo; <a class=\"read-more-link\" href=\"http:\/\/blue.yn.cn\/?p=1560\">\u9605\u8bfb\u5168\u6587<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15],"tags":[],"class_list":["post-1560","post","type-post","status-publish","format-standard","hentry","category-zabbix"],"_links":{"self":[{"href":"http:\/\/blue.yn.cn\/index.php?rest_route=\/wp\/v2\/posts\/1560","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/blue.yn.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blue.yn.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blue.yn.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blue.yn.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1560"}],"version-history":[{"count":4,"href":"http:\/\/blue.yn.cn\/index.php?rest_route=\/wp\/v2\/posts\/1560\/revisions"}],"predecessor-version":[{"id":1836,"href":"http:\/\/blue.yn.cn\/index.php?rest_route=\/wp\/v2\/posts\/1560\/revisions\/1836"}],"wp:attachment":[{"href":"http:\/\/blue.yn.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1560"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blue.yn.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1560"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blue.yn.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1560"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}