<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>bobpeers -&#62; blog &#187; script</title>
	<atom:link href="http://blog.bobpeers.com/tag/script/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.bobpeers.com</link>
	<description>Better late than never</description>
	<lastBuildDate>Fri, 24 Jun 2011 12:34:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Toggle Windows Proxy Settings</title>
		<link>http://blog.bobpeers.com/2008/12/19/toggle-windows-proxy-settings/</link>
		<comments>http://blog.bobpeers.com/2008/12/19/toggle-windows-proxy-settings/#comments</comments>
		<pubDate>Fri, 19 Dec 2008 11:11:22 +0000</pubDate>
		<dc:creator>Bob Peers</dc:creator>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[proxy]]></category>
		<category><![CDATA[proxyenable]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[toggle]]></category>

		<guid isPermaLink="false">http://blog.bobpeers.com/2008/12/19/toggle-windows-proxy-settings/</guid>
		<description><![CDATA[If you use a laptop both at home and at work it gets really annoying having to switch between using and not using a proxy server to connect to the internet. Having found quite a few sites explaining how to get the ProxyEnable registry value it&#8217;s pretty trivial to make a VBScript that toggles the [...]]]></description>
			<content:encoded><![CDATA[<p>If you use a laptop both at home and at work it gets really annoying having to switch between using and not using a proxy server to connect to the internet.</p>
<p>Having found quite a few sites <a href="http://www.microsoft.com/technet/scriptcenter/resources/qanda/may05/hey0519.mspx">explaining</a> how to get the ProxyEnable registry value it&#8217;s pretty trivial to make a VBScript that toggles the flag on and off. Just save this script in a file with a .vbs extension and double click to run. Each time it runs it will just toggle the proxy on and off .</p>
<p>I could write the usual warning about modifying the registry but we&#8217;re all adults here&#8230;.</p>
<pre>Const HKEY_CURRENT_USER = &#038;H80000001
strComputer = "."
Set objRegistry = GetObject("winmgmts:\\" &#038; strComputer &#038; "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings"
strValueName = "ProxyEnable"
objRegistry.GetDWORDValue HKEY_CURRENT_USER, strKeyPath, strValueName, dwValue
if dwValue=0 then
	dwValue=1
else
	dwValue=0
end if
objRegistry.SetDWORDValue HKEY_CURRENT_USER, strKeyPath, strValueName, dwValue
if dwValue=1 then
	msg="Proxy Enabled"
else
	msg="Proxy Disabled"
end if
msgbox msg,64,"Proxy Toggle"
</pre>
<p><!--[if IE]><iframe frameborder="0" allowTransparency="true" class="addtoany_special_service twitter_tweet" src="http://platform.twitter.com/widgets/tweet_button.html?url=http%3A%2F%2Fblog.bobpeers.com%2F2008%2F12%2F19%2Ftoggle-windows-proxy-settings%2F&amp;counturl=http%3A%2F%2Fblog.bobpeers.com%2F2008%2F12%2F19%2Ftoggle-windows-proxy-settings%2F&amp;count=none&amp;text=Toggle%20Windows%20Proxy%20Settings" scrolling="no" style="border:none;overflow:hidden;width:55px;height:20px"></iframe><![endif]--><!--[if !IE]><!--><iframe class="addtoany_special_service twitter_tweet" src="http://platform.twitter.com/widgets/tweet_button.html?url=http%3A%2F%2Fblog.bobpeers.com%2F2008%2F12%2F19%2Ftoggle-windows-proxy-settings%2F&amp;counturl=http%3A%2F%2Fblog.bobpeers.com%2F2008%2F12%2F19%2Ftoggle-windows-proxy-settings%2F&amp;count=none&amp;text=Toggle%20Windows%20Proxy%20Settings" scrolling="no" style="border:none;overflow:hidden;width:55px;height:20px"></iframe><!--<![endif]--><!--[if IE]><iframe frameborder="0" allowTransparency="true" class="addtoany_special_service facebook_like" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fblog.bobpeers.com%2F2008%2F12%2F19%2Ftoggle-windows-proxy-settings%2F&amp;layout=button_count&amp;show_faces=false&amp;width=75&amp;action=like&amp;colorscheme=light&amp;height=20&amp;ref=addtoany" scrolling="no" style="border:none;overflow:hidden;width:90px;height:21px"></iframe><![endif]--><!--[if !IE]><!--><iframe class="addtoany_special_service facebook_like" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fblog.bobpeers.com%2F2008%2F12%2F19%2Ftoggle-windows-proxy-settings%2F&amp;layout=button_count&amp;show_faces=false&amp;width=75&amp;action=like&amp;colorscheme=light&amp;height=20&amp;ref=addtoany" scrolling="no" style="border:none;overflow:hidden;width:90px;height:21px"></iframe><!--<![endif]--><!--[if IE]><iframe frameborder="0" allowTransparency="true" class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fblog.bobpeers.com%2F2008%2F12%2F19%2Ftoggle-windows-proxy-settings%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><![endif]--><!--[if !IE]><!--><iframe class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fblog.bobpeers.com%2F2008%2F12%2F19%2Ftoggle-windows-proxy-settings%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><!--<![endif]--><a class="a2a_button_google_bookmarks" href="http://www.addtoany.com/add_to/google_bookmarks?linkurl=http%3A%2F%2Fblog.bobpeers.com%2F2008%2F12%2F19%2Ftoggle-windows-proxy-settings%2F&amp;linkname=Toggle%20Windows%20Proxy%20Settings" title="Google Bookmarks" rel="nofollow" target="_blank"><img src="http://blog.bobpeers.com/wp-content/plugins/add-to-any/icons/google.png" width="16" height="16" alt="Google Bookmarks"/></a><a class="a2a_button_evernote" href="http://www.addtoany.com/add_to/evernote?linkurl=http%3A%2F%2Fblog.bobpeers.com%2F2008%2F12%2F19%2Ftoggle-windows-proxy-settings%2F&amp;linkname=Toggle%20Windows%20Proxy%20Settings" title="Evernote" rel="nofollow" target="_blank"><img src="http://blog.bobpeers.com/wp-content/plugins/add-to-any/icons/evernote.png" width="16" height="16" alt="Evernote"/></a><a class="a2a_button_google_gmail" href="http://www.addtoany.com/add_to/google_gmail?linkurl=http%3A%2F%2Fblog.bobpeers.com%2F2008%2F12%2F19%2Ftoggle-windows-proxy-settings%2F&amp;linkname=Toggle%20Windows%20Proxy%20Settings" title="Google Gmail" rel="nofollow" target="_blank"><img src="http://blog.bobpeers.com/wp-content/plugins/add-to-any/icons/gmail.png" width="16" height="16" alt="Google Gmail"/></a><a class="a2a_button_hotmail" href="http://www.addtoany.com/add_to/hotmail?linkurl=http%3A%2F%2Fblog.bobpeers.com%2F2008%2F12%2F19%2Ftoggle-windows-proxy-settings%2F&amp;linkname=Toggle%20Windows%20Proxy%20Settings" title="Hotmail" rel="nofollow" target="_blank"><img src="http://blog.bobpeers.com/wp-content/plugins/add-to-any/icons/live.png" width="16" height="16" alt="Hotmail"/></a><a class="a2a_button_wordpress" href="http://www.addtoany.com/add_to/wordpress?linkurl=http%3A%2F%2Fblog.bobpeers.com%2F2008%2F12%2F19%2Ftoggle-windows-proxy-settings%2F&amp;linkname=Toggle%20Windows%20Proxy%20Settings" title="WordPress" rel="nofollow" target="_blank"><img src="http://blog.bobpeers.com/wp-content/plugins/add-to-any/icons/wordpress.png" width="16" height="16" alt="WordPress"/></a><a class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fblog.bobpeers.com%2F2008%2F12%2F19%2Ftoggle-windows-proxy-settings%2F&amp;linkname=Toggle%20Windows%20Proxy%20Settings" title="LinkedIn" rel="nofollow" target="_blank"><img src="http://blog.bobpeers.com/wp-content/plugins/add-to-any/icons/linkedin.png" width="16" height="16" alt="LinkedIn"/></a><a class="a2a_button_facebook" href="http://www.addtoany.com/add_to/facebook?linkurl=http%3A%2F%2Fblog.bobpeers.com%2F2008%2F12%2F19%2Ftoggle-windows-proxy-settings%2F&amp;linkname=Toggle%20Windows%20Proxy%20Settings" title="Facebook" rel="nofollow" target="_blank"><img src="http://blog.bobpeers.com/wp-content/plugins/add-to-any/icons/facebook.png" width="16" height="16" alt="Facebook"/></a><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fblog.bobpeers.com%2F2008%2F12%2F19%2Ftoggle-windows-proxy-settings%2F&amp;linkname=Toggle%20Windows%20Proxy%20Settings" title="Delicious" rel="nofollow" target="_blank"><img src="http://blog.bobpeers.com/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.bobpeers.com%2F2008%2F12%2F19%2Ftoggle-windows-proxy-settings%2F&amp;title=Toggle%20Windows%20Proxy%20Settings" id="wpa2a_2"><img src="http://blog.bobpeers.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.bobpeers.com/2008/12/19/toggle-windows-proxy-settings/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Trying to Write a Shutdown Script</title>
		<link>http://blog.bobpeers.com/2008/10/21/trying-to-write-a-shutdown-script/</link>
		<comments>http://blog.bobpeers.com/2008/10/21/trying-to-write-a-shutdown-script/#comments</comments>
		<pubDate>Tue, 21 Oct 2008 12:14:45 +0000</pubDate>
		<dc:creator>Bob Peers</dc:creator>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[init]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[shutdown]]></category>
		<category><![CDATA[upstart]]></category>

		<guid isPermaLink="false">http://blog.bobpeers.com/2008/10/21/trying-to-write-a-shutdown-script/</guid>
		<description><![CDATA[I&#8217;ve been trying to create a python script runs on shutdown or reboot. First I tried using the init system by placing the script into the /etc/init.d directory and then creating symlinks to the rc0 and rc6 directories so it runs shutdown and restart (all as root). # cp myscript.py /etc/init.d # ln -s /etc/init.d/myscript.py [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been trying to create a python script runs on shutdown or reboot. First I tried using the <a href="http://www.redhat.com/docs/manuals/linux/RHL-9-Manual/ref-guide/s1-boot-init-shutdown-process.html">init</a> system by placing the script into the /etc/init.d directory and then creating symlinks to the rc0 and rc6 directories so it runs shutdown and restart (all as root).</p>
<pre># cp myscript.py /etc/init.d
# ln -s /etc/init.d/myscript.py /etc/rc0.d/K10myscript.py
# ln -s /etc/init.d/myscript.py /etc/rc6.d/K10myscript.py
</pre>
<p>This doesn&#8217;t work, at least on Fedora, I think due to the fact that the init system checks for the <a href="http://www.redhat.com/magazine/008jun05/departments/tips_tricks/">presence of a file in /var/lock/subsys</a>. Essentially the system checks whether a service is running (the lock file exists) before deciding to run the script.</p>
<p>In this case I would have to add my script as a service using <a href="http://www.linux.com/feature/46892">chkconfig -add</a> that starts on boot and creates the lock file. This is fine but what if I just want to run a simple script and not a service.</p>
<p>Next I looked at <a href="http://upstart.ubuntu.com/">Upstart</a>, the replacement for init scripts developed by Ubuntu but now the default in Fedora 9. This is compatible with the old init system but much more flexible. Following <a href="http://www.linux.com/feature/125977">this great guide</a> I tried to implement this using Upstart. Here&#8217;s my script saved in the /etc/event.d/ directory.</p>
<pre># Run my script on shutdown, reboot and runme events
start on runlevel 0     # Shutdown
start on runlevel 6     # Reboot
start on runme          # testing event
script
exec "/home/username/network_usage.py"
end script
</pre>
<p>I tested the script by emitting the runme event.</p>
<pre># /sbin/initctl emit runme
runme
network-usage (start) waiting
network-usage (start) starting
network-usage (start) pre-start
network-usage (start) spawned, process 3673
network-usage (start) post-start, (main) process 3673
network-usage (start) running, process 3673
network-usage (stop) running
network-usage (stop) stopping
network-usage (stop) killed
network-usage (stop) post-stop
network-usage (stop) waiting
initctl: runme event failed
</pre>
<p>Basically the script fails. I tried to run a bash script that calls the python script but that also fails. Upstart seems really easy to use and it&#8217;s much easier to test since you can create fictional events but I&#8217;m frustrated by my inability to run a simple python script.</p>
<p>I realise that I could write a bash script instead of a python script and it will probably work, or I could put my script in .bash_logout but that would run on user logout and not only on shutdown and reboot.</p>
<p>If anyone has a solution I&#8217;d be happy to hear.</p>
<p><!--[if IE]><iframe frameborder="0" allowTransparency="true" class="addtoany_special_service twitter_tweet" src="http://platform.twitter.com/widgets/tweet_button.html?url=http%3A%2F%2Fblog.bobpeers.com%2F2008%2F10%2F21%2Ftrying-to-write-a-shutdown-script%2F&amp;counturl=http%3A%2F%2Fblog.bobpeers.com%2F2008%2F10%2F21%2Ftrying-to-write-a-shutdown-script%2F&amp;count=none&amp;text=Trying%20to%20Write%20a%20Shutdown%20Script" scrolling="no" style="border:none;overflow:hidden;width:55px;height:20px"></iframe><![endif]--><!--[if !IE]><!--><iframe class="addtoany_special_service twitter_tweet" src="http://platform.twitter.com/widgets/tweet_button.html?url=http%3A%2F%2Fblog.bobpeers.com%2F2008%2F10%2F21%2Ftrying-to-write-a-shutdown-script%2F&amp;counturl=http%3A%2F%2Fblog.bobpeers.com%2F2008%2F10%2F21%2Ftrying-to-write-a-shutdown-script%2F&amp;count=none&amp;text=Trying%20to%20Write%20a%20Shutdown%20Script" scrolling="no" style="border:none;overflow:hidden;width:55px;height:20px"></iframe><!--<![endif]--><!--[if IE]><iframe frameborder="0" allowTransparency="true" class="addtoany_special_service facebook_like" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fblog.bobpeers.com%2F2008%2F10%2F21%2Ftrying-to-write-a-shutdown-script%2F&amp;layout=button_count&amp;show_faces=false&amp;width=75&amp;action=like&amp;colorscheme=light&amp;height=20&amp;ref=addtoany" scrolling="no" style="border:none;overflow:hidden;width:90px;height:21px"></iframe><![endif]--><!--[if !IE]><!--><iframe class="addtoany_special_service facebook_like" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fblog.bobpeers.com%2F2008%2F10%2F21%2Ftrying-to-write-a-shutdown-script%2F&amp;layout=button_count&amp;show_faces=false&amp;width=75&amp;action=like&amp;colorscheme=light&amp;height=20&amp;ref=addtoany" scrolling="no" style="border:none;overflow:hidden;width:90px;height:21px"></iframe><!--<![endif]--><!--[if IE]><iframe frameborder="0" allowTransparency="true" class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fblog.bobpeers.com%2F2008%2F10%2F21%2Ftrying-to-write-a-shutdown-script%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><![endif]--><!--[if !IE]><!--><iframe class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fblog.bobpeers.com%2F2008%2F10%2F21%2Ftrying-to-write-a-shutdown-script%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><!--<![endif]--><a class="a2a_button_google_bookmarks" href="http://www.addtoany.com/add_to/google_bookmarks?linkurl=http%3A%2F%2Fblog.bobpeers.com%2F2008%2F10%2F21%2Ftrying-to-write-a-shutdown-script%2F&amp;linkname=Trying%20to%20Write%20a%20Shutdown%20Script" title="Google Bookmarks" rel="nofollow" target="_blank"><img src="http://blog.bobpeers.com/wp-content/plugins/add-to-any/icons/google.png" width="16" height="16" alt="Google Bookmarks"/></a><a class="a2a_button_evernote" href="http://www.addtoany.com/add_to/evernote?linkurl=http%3A%2F%2Fblog.bobpeers.com%2F2008%2F10%2F21%2Ftrying-to-write-a-shutdown-script%2F&amp;linkname=Trying%20to%20Write%20a%20Shutdown%20Script" title="Evernote" rel="nofollow" target="_blank"><img src="http://blog.bobpeers.com/wp-content/plugins/add-to-any/icons/evernote.png" width="16" height="16" alt="Evernote"/></a><a class="a2a_button_google_gmail" href="http://www.addtoany.com/add_to/google_gmail?linkurl=http%3A%2F%2Fblog.bobpeers.com%2F2008%2F10%2F21%2Ftrying-to-write-a-shutdown-script%2F&amp;linkname=Trying%20to%20Write%20a%20Shutdown%20Script" title="Google Gmail" rel="nofollow" target="_blank"><img src="http://blog.bobpeers.com/wp-content/plugins/add-to-any/icons/gmail.png" width="16" height="16" alt="Google Gmail"/></a><a class="a2a_button_hotmail" href="http://www.addtoany.com/add_to/hotmail?linkurl=http%3A%2F%2Fblog.bobpeers.com%2F2008%2F10%2F21%2Ftrying-to-write-a-shutdown-script%2F&amp;linkname=Trying%20to%20Write%20a%20Shutdown%20Script" title="Hotmail" rel="nofollow" target="_blank"><img src="http://blog.bobpeers.com/wp-content/plugins/add-to-any/icons/live.png" width="16" height="16" alt="Hotmail"/></a><a class="a2a_button_wordpress" href="http://www.addtoany.com/add_to/wordpress?linkurl=http%3A%2F%2Fblog.bobpeers.com%2F2008%2F10%2F21%2Ftrying-to-write-a-shutdown-script%2F&amp;linkname=Trying%20to%20Write%20a%20Shutdown%20Script" title="WordPress" rel="nofollow" target="_blank"><img src="http://blog.bobpeers.com/wp-content/plugins/add-to-any/icons/wordpress.png" width="16" height="16" alt="WordPress"/></a><a class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fblog.bobpeers.com%2F2008%2F10%2F21%2Ftrying-to-write-a-shutdown-script%2F&amp;linkname=Trying%20to%20Write%20a%20Shutdown%20Script" title="LinkedIn" rel="nofollow" target="_blank"><img src="http://blog.bobpeers.com/wp-content/plugins/add-to-any/icons/linkedin.png" width="16" height="16" alt="LinkedIn"/></a><a class="a2a_button_facebook" href="http://www.addtoany.com/add_to/facebook?linkurl=http%3A%2F%2Fblog.bobpeers.com%2F2008%2F10%2F21%2Ftrying-to-write-a-shutdown-script%2F&amp;linkname=Trying%20to%20Write%20a%20Shutdown%20Script" title="Facebook" rel="nofollow" target="_blank"><img src="http://blog.bobpeers.com/wp-content/plugins/add-to-any/icons/facebook.png" width="16" height="16" alt="Facebook"/></a><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fblog.bobpeers.com%2F2008%2F10%2F21%2Ftrying-to-write-a-shutdown-script%2F&amp;linkname=Trying%20to%20Write%20a%20Shutdown%20Script" title="Delicious" rel="nofollow" target="_blank"><img src="http://blog.bobpeers.com/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.bobpeers.com%2F2008%2F10%2F21%2Ftrying-to-write-a-shutdown-script%2F&amp;title=Trying%20to%20Write%20a%20Shutdown%20Script" id="wpa2a_4"><img src="http://blog.bobpeers.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.bobpeers.com/2008/10/21/trying-to-write-a-shutdown-script/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

