<?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>Zenovation's Blog &#187; bash</title>
	<atom:link href="http://zenovations.com/blog/tag/bash/feed/" rel="self" type="application/rss+xml" />
	<link>http://zenovations.com/blog</link>
	<description>A blog about web design, programming, hosting, and virtualmin hacks</description>
	<lastBuildDate>Wed, 28 Jul 2010 23:33:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Sending Mail From Bash Scripts with an Attachment</title>
		<link>http://zenovations.com/blog/2010/04/sending-mail-from-bash-scripts-with-an-attachment/</link>
		<comments>http://zenovations.com/blog/2010/04/sending-mail-from-bash-scripts-with-an-attachment/#comments</comments>
		<pubDate>Tue, 27 Apr 2010 14:06:02 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[mail]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Technical]]></category>

		<guid isPermaLink="false">http://zenovations.com/blog/?p=186</guid>
		<description><![CDATA[Here is a great little tut on getting started in Bash. I&#8217;d recommend it to anyone trying to hack their way into a shell script. Here is a quick script for sending an email: ?View Code BASH#!/bin/bash &#160; # Subject of email SUBJECT=&#34;Test email with attachment from a bash script&#34; &#160; # Where to send [...]]]></description>
			<content:encoded><![CDATA[<p>Here is <a href="http://www.linux.org/lessons/advanced/x1110.html">a great little tut on getting started in Bash</a>. I&#8217;d recommend it to anyone trying to hack their way into a shell script.</p>
<p>Here is a quick script for sending an email:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p186code2'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p1862"><td class="code" id="p186code2"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Subject of email</span>
<span style="color: #007800;">SUBJECT</span>=<span style="color: #ff0000;">&quot;Test email with attachment from a bash script&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Where to send it</span>
<span style="color: #007800;">TO_ADDRESS</span>=<span style="color: #ff0000;">&quot;your@email.com&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Where the attachment is</span>
<span style="color: #007800;">ATTACHMENT_FILE</span>=<span style="color: #ff0000;">&quot;/tmp/attachment.txt&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># For fun, let's put something into the attachment</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;This goes into the file.&quot;</span>  <span style="color: #000000; font-weight: bold;">&gt;</span>  <span style="color: #007800;">$ATTACHMENT_FILE</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;This appends to the file.&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$ATTACHMENT_FILE</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># send the message</span>
<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>mail <span style="color: #660033;">-s</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$SUBJECT</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$TO_ADDRESS</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #007800;">$ATTACHMENT_FILE</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://zenovations.com/blog/2010/04/sending-mail-from-bash-scripts-with-an-attachment/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to Run a Cygwin Command From Windows Scheduler (Scheduled Tasks)</title>
		<link>http://zenovations.com/blog/2009/06/how-to-run-a-cygwin-command-from-windows-scheduler-scheduled-tasks/</link>
		<comments>http://zenovations.com/blog/2009/06/how-to-run-a-cygwin-command-from-windows-scheduler-scheduled-tasks/#comments</comments>
		<pubDate>Wed, 03 Jun 2009 19:42:31 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[cron]]></category>
		<category><![CDATA[cygwin]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://zenovations.com/blog/?p=125</guid>
		<description><![CDATA[After repeated problems setting up crond to run in cygwin (it just doesn&#8217;t like the user accounts, no matter how enthusiastically I argue that I&#8217;m me), I spent some time figuring out how to run a Cygwin command as a scheduled task from Windows scheduler. Here is what I figured out. Based on this mail [...]]]></description>
			<content:encoded><![CDATA[<p>After repeated problems setting up crond to run in cygwin (it just doesn&#8217;t like the user accounts, no matter how enthusiastically I argue that I&#8217;m me), I spent some time figuring out how to run a Cygwin command as a scheduled task from Windows scheduler. Here is what I figured out.</p>
<p>Based on <a href="http://www.mail-archive.com/cygwin@cygwin.com/msg71014.html">this mail archive post</a>, I created the following cygrun.bat file:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p125code6'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p1256"><td class="code" id="p125code6"><pre class="bash" style="font-family:monospace;">    <span style="color: #000000; font-weight: bold;">@</span><span style="color: #7a0874; font-weight: bold;">echo</span> off
    rem <span style="color: #000000; font-weight: bold;">set</span> <span style="color: #007800;">HOME</span>=c:\
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #ff0000;">&quot;%DEF_PATH%&quot;</span>==<span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #000000; font-weight: bold;">set</span> <span style="color: #007800;">DEF_PATH</span>=<span style="color: #000000; font-weight: bold;">%</span>PATH<span style="color: #000000; font-weight: bold;">%</span>
    <span style="color: #000000; font-weight: bold;">set</span> <span style="color: #007800;">PATH</span>=c:\cygwin\bin;<span style="color: #000000; font-weight: bold;">%</span>DEF_PATH<span style="color: #000000; font-weight: bold;">%</span>
    <span style="color: #000000; font-weight: bold;">set</span> <span style="color: #007800;">myargs</span>=<span style="color: #000000; font-weight: bold;">%*</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #ff0000;">&quot;%myargs%&quot;</span> == <span style="color: #ff0000;">&quot;&quot;</span> goto noarg
    rem <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000; font-weight: bold;">%</span>myargs<span style="color: #000000; font-weight: bold;">%</span>
    <span style="color: #c20cb9; font-weight: bold;">bash</span> <span style="color: #660033;">--rcfile</span> <span style="color: #000000; font-weight: bold;">%</span>HOME<span style="color: #000000; font-weight: bold;">%/</span>.bashrc <span style="color: #660033;">-i</span> <span style="color: #660033;">-c</span> <span style="color: #ff0000;">&quot;%myargs%&quot;</span> 
    c:
    rem pause
    <span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #000000;">1</span>
    goto <span style="color: #7a0874; font-weight: bold;">exit</span>
    :noarg
&nbsp;
    rxvt <span style="color: #660033;">-e</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">bash</span> <span style="color: #660033;">--login</span> <span style="color: #660033;">-i</span>
&nbsp;
    :<span style="color: #7a0874; font-weight: bold;">exit</span>
    <span style="color: #7a0874; font-weight: bold;">exit</span></pre></td></tr></table></div>

<p>Then I tested the script from the command line as follows, until I had the syntax just so:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p125code7'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p1257"><td class="code" id="p125code7"><pre class="bash" style="font-family:monospace;">c:
<span style="color: #7a0874; font-weight: bold;">cd</span> \cygwin
cygrun.bat cygwin_script arg1 arg2</pre></td></tr></table></div>

<p>Once I was able to run it happily, I added the scheduled task as follows:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p125code8'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p1258"><td class="code" id="p125code8"><pre class="bash" style="font-family:monospace;">    Run: C:\WINDOWS\system32\CMD.EXE <span style="color: #000000; font-weight: bold;">/</span>x <span style="color: #000000; font-weight: bold;">/</span>c start <span style="color: #ff0000;">&quot;Some title&quot;</span> <span style="color: #000000; font-weight: bold;">/</span>min
c:\cygwin\cygrun.bat cygwin_script arg1 arg2
    Start In: c:\cygwin     <span style="color: #000000; font-weight: bold;">&lt;</span>-- must be a real disk drive and path
    Run <span style="color: #c20cb9; font-weight: bold;">as</span>: domain\username</pre></td></tr></table></div>

<p>Unfortunately, I was never able to figure out how to redirect stdout and stderr. I tried plenty of variations on &#8220;>> /some/path/to/log.txt 2>&#038;1&#8243; with no joy. Instead, I just changed all the commands in the script and added that line on to each echo statement. Sad, but functional.</p>
]]></content:encoded>
			<wfw:commentRss>http://zenovations.com/blog/2009/06/how-to-run-a-cygwin-command-from-windows-scheduler-scheduled-tasks/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
