<?xml version="1.0" encoding="iso-8859-1"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:admin="http://webns.net/mvcb/"
xmlns="http://purl.org/rss/1.0/">
<channel rdf:about="http://aplawrence.com//rss/fullShell.rdf">
<title>Shell Site News at A.P.Lawrence.com</title>
<link>http://aplawrence.com/</link>
<description>
Shell feed at aplawrence.com: Thousands of articles, reviews, consultants listings, skills tests, opinion, how-to's for Unix, Linux and Mac OS X, networking, web site maintenance and more.. 
</description>
<sy:updatePeriod>hourly</sy:updatePeriod>
<sy:updateFrequency>6</sy:updateFrequency>
<sy:updateBase>2008-01-01T00:00+00:00</sy:updateBase>
<dc:language>en</dc:language>
<dc:publisher>A.P. Lawrence</dc:publisher>
<dc:rights>Copyright  A.P. Lawrence</dc:rights>
<dc:creator>A.P. Lawrence (mailto:rssfeeds@aplawrence.com)</dc:creator>
<dc:date>2017-02-17T10:37:54+00:00</dc:date>
<image rdf:resource="http://aplawrence.com/image21.gif">
</image>
<items>
<rdf:Seq>
<rdf:li rdf:resource="http://aplawrence.com/Forum/run-command-at-specific-time.html" />
<rdf:li rdf:resource="http://aplawrence.com/Forum/date-on-saturday.html" />
<rdf:li rdf:resource="http://aplawrence.com/Forum/send-signal-to-process.html" />
<rdf:li rdf:resource="http://aplawrence.com/Forum/testing-and-moving-files.html" />
<rdf:li rdf:resource="http://aplawrence.com/Forum/why-variable-becomes-blank-in-script.html" />
<rdf:li rdf:resource="http://aplawrence.com/Books/tc_command_line.html" />
</rdf:Seq>
</items>
</channel>
<image rdf:about="http://aplawrence.com/image21.gif">
<title>A.P.Lawrence Logo</title>
<url>http://aplawrence.com/image21.gif</url>
<link>http://aplawrence.com</link>
</image>


<item rdf:about="http://aplawrence.com/Forum/run-command-at-specific-time.html">
<title>Running a command at a particular time  </title>
<description>
<![CDATA[

<!-- <html><head><title>Running a command at a particular time</title></head><body> -->

<!-- 2015/08/06 -->


<p>Anonymous asks: <br />
<p><i>I have a cron job that runs every hour. Within that script I need to test for specific times. For example, if today is the 27th and it is 4 AM, I need to run another script.</i></p>
<p>Of course you could do this with separate cron jobs, but if you want to maintain one script that you'll run hourly, it would look something like this:</p> 



<pre>
#!/bin/bash
DOM=`date +%d`
HR=`date +%H`
if [ $DOM -eq 27 ]
then
  if [ $HR -eq 05 ]
  then 
  echo foo
  yourcommand
  fi
fi
</pre>
<p>Most of us wouldn't write it like that, though. We'd do:</p>
<pre>
#!/bin/bash
DOM=`date +%d`
HR=`date +%H`
if [ $DOM -eq 27 -a $HR -eq 04 ]
then
  echo foo
  yourcommand
fi
</pre>
<p>Watch your spacing - can't do  "if [$HR -eq 05 ]" (no space after "[").</p>




<p style="word-break: break-word; max-width: 100%; color: rgb(70, 70, 70); font-family: -apple-system-font; font-size: 17px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 24px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-tap-highlight-color: rgba(26, 26, 26, 0.301961); -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;">-- This feed and its contents are the property of A.P. Lawrence, and use is subject to our terms. It may be used for personal consumption, but may not be distributed on a website.</p><br class="Apple-interchange-newline">

]]>
</description>
<link>http://aplawrence.com/Forum/run-command-at-specific-time.html</link>
</item>
<item rdf:about="http://aplawrence.com/Forum/date-on-saturday.html">
<title>How can I find out when our anniversary falls on a Saturday?  </title>
<description>
<![CDATA[

<!-- <html><head><title>How can I find out when our anniversary falls on a Saturday?</title></head><body> -->

<!-- 2015/08/05 -->


<p>Anonymous asks: <br />
<p><i>How can I find out when our anniversary falls on a Saturday? I thought it would be easy, but it doesn't seem to be?</i></p>
<p>Actually, Google can help with this.  For example, just type in your browser window "what day is 7/11/2020":</p>
<div style="text-align:center">

<p><a href="http://aplawrence.com/cgi-bin/showpic.pl?image=date-on-saturday_lg.jpg&amp;mytitle=Google%20knows%20what%20day%20it%20is&amp;returnpage=Forum/date-on-saturday.html&amp;returntitle=How%20can%20I%20find%20out%20when%20our%20anniversary%20falls%20on%20a%20Saturday?"><img src="http://aplawrence.com/images/date-on-saturday.jpg" alt="Google knows what day it is" title="Google knows what day it is (click for larger view)" /></a><br /></p>

</div>
<p>In Linux/Unix Bash, there's a quick command line that will find these dates:</p>

<pre>
$ for i in {2016..2050}; do echo -n "$i ";cal 07 $i | grep 11; done| grep "10 11$"
2020  5  6  7  8  9 10 11
2026  5  6  7  8  9 10 11
2037  5  6  7  8  9 10 11
2043  5  6  7  8  9 10 11
2048  5  6  7  8  9 10 11
</pre>
<p>Note that can look backward just as easily:</p>
<pre>
$ for i in {2016..1960}; do echo -n "$i ";cal 07 $i | grep 11; done| grep "10 11$"
2015  5  6  7  8  9 10 11
2009  5  6  7  8  9 10 11
1998  5  6  7  8  9 10 11
1992  5  6  7  8  9 10 11
1987  5  6  7  8  9 10 11
1981  5  6  7  8  9 10 11
1970  5  6  7  8  9 10 11
1964  5  6  7  8  9 10 11
</pre>

<p>Somewhere there may be an online calculator for this. I couldn't find one, but I did find these:</p>
<p><a href="http://www.timeanddate.com/date/weekday.html">Weekday Calculator – What Day is this Date?</a></p>

<p><a href="https://en.wikipedia.org/wiki/Doomsday_rule">Doomsday Rule</a></p>
<p><a href="http://english.stackexchange.com/questions/176967/is-there-a-term-for-an-anniversary-that-falls-on-the-same-day-of-the-week-as-its"> Is there a term for an anniversary that falls on the same day of the week as its original date?</a></p>
<p><a href="http://www.cpearson.com/excel/holidays.htm">Holidays</a></p>
<p><a href="http://www.javaworld.com/article/2077543/learn-java/java-tip-44--calculating-holidays-and-their-observances.html">Calculating holidays and their observances</a></p>
<p><a href="http://answers.microsoft.com/en-us/office/forum/officeversion_other-excel/calculate-next-workday-when-date-falls-on-weekend/24a0629d-a444-4933-bcee-699cb0abef30">Calculate next workday when date falls on weekend</a></p>
<p><a href="https://community.qlik.com/docs/DOC-5741">Calculating Holidays in script</a></p>



<p style="word-break: break-word; max-width: 100%; color: rgb(70, 70, 70); font-family: -apple-system-font; font-size: 17px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 24px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-tap-highlight-color: rgba(26, 26, 26, 0.301961); -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;">-- This feed and its contents are the property of A.P. Lawrence, and use is subject to our terms. It may be used for personal consumption, but may not be distributed on a website.</p><br class="Apple-interchange-newline">

]]>
</description>
<link>http://aplawrence.com/Forum/date-on-saturday.html</link>
</item>
<item rdf:about="http://aplawrence.com/Forum/send-signal-to-process.html">
<title>I need to send a kill -1 to a process  </title>
<description>
<![CDATA[

<!-- <html><head><title>I need to send a kill -1 to a process</title></head><body> -->

<!-- 2015/07/30 -->


<p>Anonymous asks: <br />
<p><i>I need to send a kill -1 to a process but I can not get the pid from a file as it's location is different on some systems</i></p>
<p>On Linux systems, that's very simple. You said your executable is "dnsmasq", so you can simply do:</p>

<pre>
killall -s 1 dnsmasq
</pre>
<p>If this isn't a Linux system or if you need the capture the PID for other reasons, do something like:</p>
<pre>
THEPID=`ps -ef|grep  dnsmasq    |grep -v grep`
</pre>
<p>and reference $THEPID wherever you need to.</p>

<p>See also <a href="http://aplawrence.com/Unixart/kill_user.html">Murder and Mayhem - How to kill user's processes</a> and <a href="http://aplawrence.com/Basics/understanding_kill.html">Understanding Kill</a>.</p>





<p style="word-break: break-word; max-width: 100%; color: rgb(70, 70, 70); font-family: -apple-system-font; font-size: 17px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 24px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-tap-highlight-color: rgba(26, 26, 26, 0.301961); -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;">-- This feed and its contents are the property of A.P. Lawrence, and use is subject to our terms. It may be used for personal consumption, but may not be distributed on a website.</p><br class="Apple-interchange-newline">

]]>
</description>
<link>http://aplawrence.com/Forum/send-signal-to-process.html</link>
</item>
<item rdf:about="http://aplawrence.com/Forum/testing-and-moving-files.html">
<title>Shell script cannot test for the existence of files  </title>
<description>
<![CDATA[

<!-- <html><head><title>Shell script cannot test for the existence of files</title></head><body> -->

<!-- 2015/07/29 -->


<p>Anonymous asks: <br />
<p><i>My shell script needs to move certain files to another location. How do I test that the files exist?</i></p>


<p>The script you supplied looks like this:</p>


<pre>
if [ -f /home/sales/*.xml ]
 then

 mv /home/sales/*.xml /tmp

fi
</pre>



<p>
Your problem is that "/home/sales/*.xml" can expand to more than one file.  The "mv" doesn't care, but test ("[") can't handle that. That's why your script won't work.<p>

<p>You can do this instead:</p>

<pre>
for i in  /home/sales/*.xml
do
mv $i /tmp
done
</pre>
<p>If there is nothing in /home/sales to match *.xml, the loop won't move anything, but will error. To suppress the errror add "2&gt;/dev/null after the "done".</p>
<p>An equivalent loop in Perl doesn't need the error redirection:</p>
<pre>
#!/usr/bin/perl
@files=&lt;foobahjj*&gt;;
foreach  (@files) {
  # Nothing in this loop will execute if there are no foobahjj* files.
  print $_
  print "goo"
}
</pre>




<p style="word-break: break-word; max-width: 100%; color: rgb(70, 70, 70); font-family: -apple-system-font; font-size: 17px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 24px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-tap-highlight-color: rgba(26, 26, 26, 0.301961); -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;">-- This feed and its contents are the property of A.P. Lawrence, and use is subject to our terms. It may be used for personal consumption, but may not be distributed on a website.</p><br class="Apple-interchange-newline">

]]>
</description>
<link>http://aplawrence.com/Forum/testing-and-moving-files.html</link>
</item>
<item rdf:about="http://aplawrence.com/Forum/why-variable-becomes-blank-in-script.html">
<title>Why does this variable become blank?  </title>
<description>
<![CDATA[

<!-- <html><head><title>Why does this variable become blank?</title></head><body> -->

<!-- 2015/07/14 -->


<p>Anonymous asks: <br />
<p><i>Why does this variable become blank? It's obviously set in the first part, but it goes away.</i></p>
<pre>
who am i | if grep tony &gt; /dev/null  2&gt;&1
 then
 echo "Setting source directory to /usr1/src"
 export src_path=/usr1/src
 echo $src_path
 else
 src_path=/usr2/src
fi
echo -e "src_path= $src_path"
</pre>
<p>What happens here is actually very simple, although it may seem baffling at first. Yes, the "if then" block sets the variable to either /usr1/src or /usr2/src, so it surprised you to find it blank in the last line which echoed "src_path= $src_path".</p>
<p>What you missed is that piping "who am i" to that "if" block caused the creation of a new shell for everything in the block. Variables changed in a new shell don't change the values in the calling shell, so $src_path was still blank.</p>
<p>Something like this will work much better:</p>


<pre>
IAM=`who am i | cut -d" " -f1`

if [ $IAM == "tony" ]
 then
 ..
</pre>
<p><i>brinan White noted that the script will work in ksh</i></p>



<p style="word-break: break-word; max-width: 100%; color: rgb(70, 70, 70); font-family: -apple-system-font; font-size: 17px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 24px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-tap-highlight-color: rgba(26, 26, 26, 0.301961); -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;">-- This feed and its contents are the property of A.P. Lawrence, and use is subject to our terms. It may be used for personal consumption, but may not be distributed on a website.</p><br class="Apple-interchange-newline">

]]>
</description>
<link>http://aplawrence.com/Forum/why-variable-becomes-blank-in-script.html</link>
</item>
<item rdf:about="http://aplawrence.com/Books/tc_command_line.html">
<title>Take Control of the Mac Command Line with Terminal  </title>
<description>
<![CDATA[



<!-- 2009/05/04 -->
<div style="float:left;padding:5%">
<img src="/images/tc_command_line.jpg" alt="Cover image" />
</div>

<div class="hReview">
<div class="item">

<p><a href="http://www.takecontrolbooks.com/command-line?aff=AFL1361639390">PDF E-book</a>.  167 pages, free updates: </p>
<ul>
<li>Take Control of the Mac Command Line with Terminal (updated 2015)</li>
<li>Joe Kissell </li>
<li>TidBits</li>
<li>9781933671550</li>

</ul><br />
<p>Old-timers like me couldn't avoid being exposed to command line interfaces - that's all we had when we started 
using computers.  Actually, that's even wrong:  when I started with computers, your input choices were front panel switches, punched cards or punched tape - command line interfaces were a big step up!</p>
<p>Younger people and people who simply started using computers a bit later weren't necessarily exposed to any command line.  Any computer they ever used had a graphical user interface and while it still may have had a command line available, there was seldom any incentive to use it.  That apparent lack of any compelling reason remains true, but in fact understanding the command line can give you much more control over your computer and allow you to accomplish some tasks much more quickly and easily.</p>
<p>That's especially true for Mac OS X which gives you a real Unix command line.  The old DOS command line in Windows is weak and anemic; Unix shells such as are provided with OS X are very powerful tools.  But how do you 
learn to use those tools effectively if you are starting from square one?</p>
<p><i><span class="fn">Take Control of the Mac Command Line with Terminal</span></i> is the answer.   <span class="summary">Joe Kissell leads you step by step from knowing absolutely nothing to having confident control of Mac OS X Terminal and the bash shell.   If you have been fearful of the OS X command line, this is where you want to start.</span></p>
<p><span class="reviewer">Tony Lawrence</span> <span class="dtreviewed">2015/05/25</span> Rating:  <span class="rating">4.5</span></p>
</div>
</div>
<br />
<p><a href="http://www.takecontrolbooks.com/command-line?aff=AFL1361639390">PDF E-book</a>.  167 pages, free updates</p>



<p style="word-break: break-word; max-width: 100%; color: rgb(70, 70, 70); font-family: -apple-system-font; font-size: 17px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 24px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-tap-highlight-color: rgba(26, 26, 26, 0.301961); -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;">-- This feed and its contents are the property of A.P. Lawrence, and use is subject to our terms. It may be used for personal consumption, but may not be distributed on a website.</p><br class="Apple-interchange-newline">

]]>
</description>
<link>http://aplawrence.com/Books/tc_command_line.html</link>
</item>
</rdf:RDF>
