{"id":420,"date":"2013-07-03T16:45:39","date_gmt":"2013-07-03T14:45:39","guid":{"rendered":"http:\/\/dety.net.ua\/?p=420"},"modified":"2013-07-03T16:45:39","modified_gmt":"2013-07-03T14:45:39","slug":"internet-channel-reservation-script","status":"publish","type":"post","link":"https:\/\/dety.net.ua\/?p=420","title":{"rendered":"Internet channel reservation script"},"content":{"rendered":"<p>My script:<\/p>\n<blockquote><p>#!\/bin\/sh<br \/>\nPATH=&#8221;\/bin:\/sbin:\/usr\/bin&#8221;<\/p>\n<p>#Main Provider Router<br \/>\nISP1=&#8221;1.1.1.1&#8243;<\/p>\n<p>#Second Provider Router<br \/>\nISP2=&#8221;2.2.2.2&#8243;<\/p>\n<p>#IF 2 channels don&#8217;t work &#8211; will be set it<br \/>\nDEFAULT_ISP=&#8221;1.1.1.1&#8243;<\/p>\n<p># IP&#8217;s for ping<br \/>\nOVER_ISP1=&#8221;1.1.1.1&#8243;<br \/>\nOVER_ISP2=&#8221;2.2.2.2&#8243;<\/p>\n<p># Local source IP&#8217;s<br \/>\nIP1=&#8221;myip1&#8243;<br \/>\nIP2=&#8221;myip2&#8243;<\/p>\n<p># Verify routes<br \/>\n#netstat -nr | grep ${OVER_ISP1} &gt;\/dev\/null 2&gt;&amp;1<br \/>\n#if [ $? != 0 ]; then<br \/>\n#\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 echo &#8220;Add static route to ${OVER_ISP1} via ${ISP1}&#8221;<br \/>\n#\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 route add ${OVER_ISP1} ${ISP1} -static<br \/>\n#fi<br \/>\n#netstat -nr | grep ${OVER_ISP2} &gt;\/dev\/null 2&gt;&amp;1<br \/>\n#if [ $? != 0 ]; then<br \/>\n# echo &#8220;Add static route to ${OVER_ISP2} via\u00a0 ${ISP2}&#8221;<br \/>\n# route add ${OVER_ISP2} ${ISP2} -static<br \/>\n#fi<br \/>\n# What is work now<br \/>\ncurrent_now=`netstat -nr | grep default | awk &#8216;{print $2}&#8217;`<br \/>\n# echo -n &#8220;ping over ISP1:&#8221;<br \/>\nping -c 2 -S ${IP1} ${OVER_ISP1} &gt;\/dev\/null 2&gt;&amp;1<br \/>\nif [ $? -eq 0 ]; then<br \/>\n#echo &#8221; [OK]&#8221;<br \/>\nISP1_stat=0<br \/>\nelse<br \/>\n#echo &#8221; [FAILED]&#8221;<br \/>\nISP1_stat=1<br \/>\nmail -s &#8220;Main Internet-channel FAILED&#8221; root &lt; \/dev\/null<br \/>\nfi<br \/>\n# echo -n &#8220;ping over ISP2:&#8221;<br \/>\nping -c 1 -S ${IP2} ${OVER_ISP2} &gt;\/dev\/null 2&gt;&amp;1<br \/>\nif [ $? -eq 0 ]; then<br \/>\n#echo &#8221; [OK]&#8221;<br \/>\nISP2_stat=0<br \/>\nif [ -f \/tmp\/isp2.tmp ]; then<br \/>\nrm \/tmp\/isp2.tmp<br \/>\nmail -s &#8220;Second Internet-channel RESTORED&#8221; root &lt; \/dev\/null<br \/>\nfi;<br \/>\nelse<br \/>\n#echo &#8221; [FAILED]&#8221;<br \/>\nISP2_stat=1<br \/>\nif [ -f \/tmp\/isp2.tmp ]; then<br \/>\necho &#8220;still nothing&#8221; &gt; \/dev\/null<br \/>\nelse<br \/>\nmail -s &#8220;Second Internet-channel FAILED&#8221; root &lt; \/dev\/null<br \/>\necho &#8220;failed&#8221; &gt; \/tmp\/isp2.tmp<br \/>\nfi<br \/>\nfi<br \/>\nif [ ${ISP1_stat} -eq 1 -a ${ISP2_stat} -eq 0 -a ${current_now} = ${ISP1} ]; then<br \/>\n#echo &#8220;ISP1 suck&#8221;<br \/>\nroute delete default<br \/>\nroute add default ${ISP2}<br \/>\nmail -s &#8220;Main Internet-channel FAILED &#8211; switching to Second&#8221; root &lt; \/dev\/null<br \/>\nfi<br \/>\nif [ ${ISP1_stat} -eq 0 -a ${current_now} != ${ISP1} ]; then<br \/>\n#echo &#8220;Back to ISP1&#8221;<br \/>\nroute delete default<br \/>\nroute add default ${ISP1}<br \/>\n\/usr\/local\/etc\/racoon\/setkey.conf<br \/>\nmail -s &#8220;Main Internet-channel OK &#8211; switching back to MAIN&#8221; root &lt; \/dev\/null<br \/>\nfi<\/p>\n<p># Check IPSEC channel<br \/>\nping -c 1 192.168.1.1 &gt;\/dev\/null 2&gt;&amp;1<br \/>\nif [ $? -ne 0 ]; then<br \/>\n\/usr\/local\/etc\/racoon\/setkey.conf &gt; \/dev\/null<br \/>\nmail -s &#8220;IPSEC channel to DC is failed &#8211; restarting rules&#8221; root &lt; \/dev\/null<br \/>\nfi<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>My script: #!\/bin\/sh PATH=&#8221;\/bin:\/sbin:\/usr\/bin&#8221; #Main Provider Router ISP1=&#8221;1.1.1.1&#8243; #Second Provider Router ISP2=&#8221;2.2.2.2&#8243; #IF 2 channels don&#8217;t work &#8211; will be set it DEFAULT_ISP=&#8221;1.1.1.1&#8243; # IP&#8217;s for ping OVER_ISP1=&#8221;1.1.1.1&#8243; OVER_ISP2=&#8221;2.2.2.2&#8243; # Local source IP&#8217;s IP1=&#8221;myip1&#8243; IP2=&#8221;myip2&#8243; # Verify routes #netstat -nr | grep ${OVER_ISP1} &gt;\/dev\/null 2&gt;&amp;1 #if [ $? != 0 ]; then #\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 echo &#8220;Add [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,13],"tags":[],"class_list":["post-420","post","type-post","status-publish","format-standard","hentry","category-freebsd","category-novosti"],"_links":{"self":[{"href":"https:\/\/dety.net.ua\/index.php?rest_route=\/wp\/v2\/posts\/420","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dety.net.ua\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dety.net.ua\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dety.net.ua\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dety.net.ua\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=420"}],"version-history":[{"count":1,"href":"https:\/\/dety.net.ua\/index.php?rest_route=\/wp\/v2\/posts\/420\/revisions"}],"predecessor-version":[{"id":421,"href":"https:\/\/dety.net.ua\/index.php?rest_route=\/wp\/v2\/posts\/420\/revisions\/421"}],"wp:attachment":[{"href":"https:\/\/dety.net.ua\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=420"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dety.net.ua\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=420"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dety.net.ua\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=420"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}