{"id":224,"date":"2009-01-25T17:33:42","date_gmt":"2009-01-25T15:33:42","guid":{"rendered":"http:\/\/blog.sqawasmi.com\/?p=224"},"modified":"2009-01-25T17:33:42","modified_gmt":"2009-01-25T15:33:42","slug":"workhome-switcher-script","status":"publish","type":"post","link":"https:\/\/blog.sqawasmi.com\/index.php\/2009\/01\/25\/workhome-switcher-script\/","title":{"rendered":"Work\/Home switcher script"},"content":{"rendered":"<p>Recently, i decided to bring my laptop to the work, so i start using it and leaving my work PC as testing machine,, also connecting to online servers through it.<\/p>\n<p>In the work we used a static IP with a static gateway for each department, also with a specific resolv.conf configuration,, at home, i use another configuration for network and internet connection,, so every time i go home, i need to reconfigure the internet,, when i go to the work, i also need to reconfigure the network.. so i decided to write a script so it help me to automate this.<\/p>\n<p>Also as i said, i will use my work PC to connect to online servers, yes i can connect through my laptop, but when i go home i must connect to the work PC so i can connect to the online servers.<\/p>\n<p>mmmmm,, so my idea was to automate the network connection and also if am at the work then each terminal i open it must login directly to my work PC,,, also my mind didn&#8217;t work from a long time maybe 3 months and i started to 4get many things so i need to refresh it somehow \ud83d\ude09<\/p>\n<p>the following is the script i wrote:<\/p>\n<blockquote><p>#!\/bin\/bash<br \/>\n##Default to be home :S<br \/>\nwhereIam=&#8217;scripts\/work-home\/work&#8217;<br \/>\ntouch ~\/$whereIam;<\/p>\n<p>while true<br \/>\ndo<br \/>\nif [ -f ~\/$whereIam ]<br \/>\nthen<br \/>\nsudo \/home\/idle-boy\/scripts\/work-home\/net_conf.sh 1 &gt; \/dev\/null<br \/>\nzenity &#8211;notification &#8211;window-icon=\/usr\/share\/icons\/Fedora\/48&#215;48\/apps\/redhat-main-menu.png &#8211;text &#8216;I am in the work!&#8217;;<br \/>\nrm -rf ~\/scripts\/work-home\/work<br \/>\nelse<br \/>\nsudo \/home\/idle-boy\/scripts\/work-home\/net_conf.sh 0 \/dev\/null<br \/>\nzenity &#8211;notification &#8211;window-icon=\/usr\/share\/icons\/HighContrast-SVG\/scalable\/emotes\/face-wink.svg &#8211;text &#8216;OoOpPps am home!?&#8217;;<br \/>\ntouch ~\/scripts\/work-home\/work<br \/>\nfi<br \/>\ndone<\/p><\/blockquote>\n<p>The script simply touch a file under ~\/scripts\/work-home\/ named &#8216;work&#8217;,, if the file exist then am in the work,, if the file not exist then am at home,, also i used zenity so it display a notification so when i want to change mode i just click on it.<\/p>\n<p>for internet configuration i wrote the script \/home\/idle-boy\/scripts\/work-home\/net_conf.sh , and i use sudo to run it as root,, the script is:<\/p>\n<blockquote><p>#!\/bin\/bash<\/p>\n<p>if [ $1 -eq 1 ]<br \/>\nthen<br \/>\n## work conf:<br \/>\n#stop network<br \/>\n\/etc\/init.d\/NetworkManager stop<br \/>\n\/etc\/init.d\/network stop<br \/>\n#configure eth0<br \/>\n\/sbin\/ifconfig eth0 192.100.80.196 netmask 255.255.254.0<br \/>\n#bring loopback interface up<br \/>\n\/sbin\/ifconfig lo up<br \/>\n#add gateway<br \/>\n\/sbin\/route add -net 0.0.0.0 gw 192.100.81.9<br \/>\n#insert resolv.conf configuration<br \/>\n#i always lock resolv.conf, so unlock it<br \/>\nchattr -i \/etc\/resolv.conf<br \/>\n&gt;\/etc\/resolv.conf<br \/>\necho &#8216;search maktoob.com&#8217; &gt;&gt; \/etc\/resolv.conf<br \/>\necho &#8216;nameserver 127.0.0.1&#8217; &gt;&gt; \/etc\/resolv.conf<br \/>\necho &#8216;nameserver 192.100.81.9&#8217; &gt;&gt; \/etc\/resolv.conf<br \/>\n#lock it again<br \/>\nchattr +i \/etc\/resolv.conf<br \/>\nelse<br \/>\n## home conf:<br \/>\n#bring up the network and NetworkManager<br \/>\n#i use NetworkManager to connect to wlan, so it take everything from the router via DHCP<br \/>\n\/etc\/init.d\/network restart<br \/>\n\/etc\/init.d\/NetworkManager restart<br \/>\n#i don&#8217;t like getting resolv.conf configuration via NetworkManager, am home!,, so:<br \/>\nchattr -i \/etc\/resolv.conf<br \/>\n&gt; \/etc\/resolv.conf<br \/>\necho &#8216;nameserver 127.0.0.1&#8217; &gt;&gt; \/etc\/resolv.conf<br \/>\necho &#8216;nameserver 212.118.0.1&#8217; &gt;&gt; \/etc\/resolv.conf<br \/>\necho &#8216;nameserver 212.118.0.2&#8217; &gt;&gt; \/etc\/resolv.conf<br \/>\nchattr +i \/etc\/resolv.conf<br \/>\nfi<\/p><\/blockquote>\n<h3>Related Images:<\/h3>","protected":false},"excerpt":{"rendered":"<p>Recently, i decided to bring my laptop to the work, so i start using it and leaving my work PC as testing machine,, also connecting to online servers through it. In the work we used a static IP with a static gateway for each department, also with a specific resolv.conf configuration,, at home, i use [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"ngg_post_thumbnail":0,"footnotes":""},"categories":[14,7],"tags":[],"class_list":["post-224","post","type-post","status-publish","format-standard","hentry","category-bash","category-scripting-cli"],"_links":{"self":[{"href":"https:\/\/blog.sqawasmi.com\/index.php\/wp-json\/wp\/v2\/posts\/224","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.sqawasmi.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.sqawasmi.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.sqawasmi.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.sqawasmi.com\/index.php\/wp-json\/wp\/v2\/comments?post=224"}],"version-history":[{"count":2,"href":"https:\/\/blog.sqawasmi.com\/index.php\/wp-json\/wp\/v2\/posts\/224\/revisions"}],"predecessor-version":[{"id":226,"href":"https:\/\/blog.sqawasmi.com\/index.php\/wp-json\/wp\/v2\/posts\/224\/revisions\/226"}],"wp:attachment":[{"href":"https:\/\/blog.sqawasmi.com\/index.php\/wp-json\/wp\/v2\/media?parent=224"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.sqawasmi.com\/index.php\/wp-json\/wp\/v2\/categories?post=224"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.sqawasmi.com\/index.php\/wp-json\/wp\/v2\/tags?post=224"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}