<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Improving an existing script in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/improving-an-existing-script/m-p/4519715#M61920</link>
    <description>I did some further testing, and the code shown below is what I inserted into the script:&lt;BR /&gt;&lt;BR /&gt;##########################################&lt;BR /&gt;read -p "Is the directory name that was entered spelled correctly &lt;YES&gt;"&lt;BR /&gt;if [ $REPLY = "no" ]; then&lt;BR /&gt;echo Reenter the patient directory name.&lt;BR /&gt;exit&lt;BR /&gt;fi&lt;BR /&gt;##########################################&lt;BR /&gt;&lt;BR /&gt;This addition appears to work as far as the users are concerned. &lt;BR /&gt;&lt;BR /&gt;Regarding your question about testing it at both ends: The test that I did was as follows, a patient directory was chosen, and the ps2pdf command was first run over the NFS mount. The calculated time for completion was approximately fifteen minutes. The generated pdf files were then deleted, and the same command was run after the .ps files were copied to a local directory, converted to pdf format, and then copied back to the source. The approximate time for completion was about five minutes. &lt;BR /&gt;&lt;/YES&gt;</description>
    <pubDate>Fri, 23 Oct 2009 19:19:30 GMT</pubDate>
    <dc:creator>Andrew Kaplan</dc:creator>
    <dc:date>2009-10-23T19:19:30Z</dc:date>
    <item>
      <title>Improving an existing script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/improving-an-existing-script/m-p/4519709#M61914</link>
      <description>Hi there --&lt;BR /&gt;&lt;BR /&gt;I have a script running on one of our workstations that converts .ps files to .pdf versions using the ps2pdf binary. The text of the script is shown below:&lt;BR /&gt;&lt;BR /&gt;##############################################&lt;BR /&gt;#!/bin/bash&lt;BR /&gt;&lt;BR /&gt;# The purpose of this script is to go to the directory in question,&lt;BR /&gt;# and convert all postscript, .ps, files located there to .pdf files.&lt;BR /&gt;&lt;BR /&gt;# Provide a list of the cases directory for the user.&lt;BR /&gt;cd /home/rsa/data/xknife_data/cases&lt;BR /&gt;&lt;BR /&gt;echo CONVERSION OF POSTSCRIPT, .ps, FILES TO ADOBE ACROBAT, .pdf, FORMAT.&lt;BR /&gt;echo&lt;BR /&gt;echo&lt;BR /&gt;echo The patients in the cases folder will now be listed for your convenience.&lt;BR /&gt;echo&lt;BR /&gt;echo It is important that you make note of the exact spelling of the directory&lt;BR /&gt;echo in question in order for this process to work.&lt;BR /&gt;echo&lt;BR /&gt;echo&lt;BR /&gt;read -p "Press the enter key to continue..."&lt;BR /&gt;&lt;BR /&gt;ls -1 | more&lt;BR /&gt;echo&lt;BR /&gt;echo&lt;BR /&gt;echo Please enter the directory that is the object of this exercise.&lt;BR /&gt;echo If you make a mistake here, hit CTRL-C to exit from the script,&lt;BR /&gt;echo and start over. &lt;BR /&gt;echo&lt;BR /&gt;read directory&lt;BR /&gt;echo Is $directory the patient in question?&lt;BR /&gt;&lt;BR /&gt;if [ -e $directory ]&lt;BR /&gt;then&lt;BR /&gt;echo "Patient directory found."&lt;BR /&gt;else&lt;BR /&gt;echo "Patient directory NOT found." &lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;# Change to the directory in question&lt;BR /&gt;cd /home/rsa/data/xknife_data/cases/$directory&lt;BR /&gt;&lt;BR /&gt;# Copy the .ps files to a local directory&lt;BR /&gt;cp -pr *.ps /tmp/ps2pdf&lt;BR /&gt;&lt;BR /&gt;# Change to the temporary directory&lt;BR /&gt;cd  /tmp/ps2pdf&lt;BR /&gt;&lt;BR /&gt;# List the files that were copied over the temporary directory&lt;BR /&gt;ls -l&lt;BR /&gt;&lt;BR /&gt;# Convert the files in the temporary directory to .pdf format.&lt;BR /&gt;for i in *.ps; &lt;BR /&gt;do ps2pdf "$i"; &lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;# Copy the .pdf files back to the original location&lt;BR /&gt;cp -pr *.pdf /home/rsa/data/xknife_data/cases/$directory&lt;BR /&gt;&lt;BR /&gt;# Remove the files from the temporary directory&lt;BR /&gt;cd /tmp/ps2pdf&lt;BR /&gt;rm -rf *.ps&lt;BR /&gt;rm -rf *.pdf&lt;BR /&gt;&lt;BR /&gt;echo The conversion of the postscript files to acrobat format is complete.&lt;BR /&gt;echo Use an ftp client application to retrieve the files from the patient directory.&lt;BR /&gt;##############################################&lt;BR /&gt;&lt;BR /&gt;I have been asked to add the following improvement to the script:&lt;BR /&gt;&lt;BR /&gt;Prompt the user to answer yes or no as to the name entered is spelled correctly. If so, the script continues, otherwise prompt the user to reenter the name of the directory again. &lt;BR /&gt;&lt;BR /&gt;I am not familar with the correct syntax to enable the item that I listed, so I was hoping someone could lend a hand here. Thanks.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 22 Oct 2009 21:31:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/improving-an-existing-script/m-p/4519709#M61914</guid>
      <dc:creator>Andrew Kaplan</dc:creator>
      <dc:date>2009-10-22T21:31:07Z</dc:date>
    </item>
    <item>
      <title>Re: Improving an existing script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/improving-an-existing-script/m-p/4519710#M61915</link>
      <description>&lt;!--!*#--&gt;Have you considered the advantages of&lt;BR /&gt;learning some basic computer programming&lt;BR /&gt;somewhere?&lt;BR /&gt;&lt;BR /&gt;&amp;gt; if [ -e $directory ]&lt;BR /&gt;&amp;gt; then&lt;BR /&gt;&amp;gt; echo "Patient directory found."&lt;BR /&gt;&amp;gt; else&lt;BR /&gt;&amp;gt; echo "Patient directory NOT found."&lt;BR /&gt;&amp;gt; fi&lt;BR /&gt;&lt;BR /&gt;So, if "$directory" exists or not, this&lt;BR /&gt;script continues on, and uses that name,&lt;BR /&gt;no matter how hopeless the task might be with&lt;BR /&gt;the name of a nonexistent directory.&lt;BR /&gt;&lt;BR /&gt;It might be more helpful to go back and ask&lt;BR /&gt;again when the user supplies a bad answer.&lt;BR /&gt;There are many ways to do this, including&lt;BR /&gt;"while", "if", and some of their relatives&lt;BR /&gt;("goto", ...).&lt;BR /&gt;&lt;BR /&gt;      man bash&lt;BR /&gt;&lt;BR /&gt;&amp;gt; ls -1 | more&lt;BR /&gt;&lt;BR /&gt;You might tell the user how to abort the&lt;BR /&gt;listing when the desired name is seen.&lt;BR /&gt;&lt;BR /&gt;With a little more effort, one might present&lt;BR /&gt;to the user a screen-full of names with&lt;BR /&gt;(shorter, easier-to-type) numbers.  For&lt;BR /&gt;example:&lt;BR /&gt;&lt;BR /&gt;1. Aardvark&lt;BR /&gt;2. Kaplan&lt;BR /&gt;3. Smith&lt;BR /&gt;4. Zamboni&lt;BR /&gt;&lt;BR /&gt;and then take a number as input.  (You could&lt;BR /&gt;then display the associated name, and ask the&lt;BR /&gt;user for confirmation before doing the work.)&lt;BR /&gt;&lt;BR /&gt;The world is filled with shell scripts which&lt;BR /&gt;do useful things in clever ways.  You might&lt;BR /&gt;try to find some, and steal their secrets.&lt;BR /&gt;&lt;BR /&gt;Or buy a book.  Or take a class.&lt;BR /&gt;&lt;BR /&gt;Or, I suppose, wait for someone here to offer&lt;BR /&gt;to do your job for you.</description>
      <pubDate>Thu, 22 Oct 2009 22:59:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/improving-an-existing-script/m-p/4519710#M61915</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2009-10-22T22:59:05Z</dc:date>
    </item>
    <item>
      <title>Re: Improving an existing script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/improving-an-existing-script/m-p/4519711#M61916</link>
      <description>&lt;!--!*#--&gt;I must have too much time on my hands.&lt;BR /&gt;&lt;BR /&gt;&amp;gt; # Copy the .ps files to a local directory&lt;BR /&gt;&lt;BR /&gt;Why?&lt;BR /&gt;&lt;BR /&gt;&amp;gt; # Copy the .pdf files back to the original location&lt;BR /&gt;&lt;BR /&gt;Again, why?  Aren't they still there?&lt;BR /&gt;&lt;BR /&gt;&amp;gt; # Copy the .pdf files back to the original location&lt;BR /&gt;&lt;BR /&gt;Can't "ps2pdf" create them there?&lt;BR /&gt;&lt;BR /&gt;&amp;gt; # Remove the files from the temporary directory&lt;BR /&gt;&lt;BR /&gt;You don't need to delete the ".ps" files if&lt;BR /&gt;you don't do the unnecessary copying.  You&lt;BR /&gt;don't need to delete the ".pdf" files if you&lt;BR /&gt;create them in the right place to begin with&lt;BR /&gt;(or if you "mv" them instead of copying&lt;BR /&gt;them, but that's still extra work).&lt;BR /&gt;&lt;BR /&gt;Miscellaneous complaints:&lt;BR /&gt;&lt;BR /&gt;&amp;gt; if [ -e $directory ]&lt;BR /&gt;&lt;BR /&gt;&amp;gt; cp -pr *.pdf /home/rsa/data/xknife_data/cases/$directory&lt;BR /&gt;&lt;BR /&gt;&amp;gt; [...]&lt;BR /&gt;&lt;BR /&gt;I hope that there are no spaces in any of&lt;BR /&gt;these directory names.&lt;BR /&gt;&lt;BR /&gt;Using "echo" with unquoted text can cause&lt;BR /&gt;unpleasant things to happen.  For example,&lt;BR /&gt;compare these:&lt;BR /&gt;      echo 'a &amp;gt; b'&lt;BR /&gt;      echo a &amp;gt; b&lt;BR /&gt;&lt;BR /&gt;For a simple example script which shows a&lt;BR /&gt;couple of basic things, consider this:&lt;BR /&gt;&lt;BR /&gt;bash$ cat example.sh&lt;BR /&gt;#!/bin/sh&lt;BR /&gt;&lt;BR /&gt;cat &amp;lt;&lt;EOD&gt;&lt;/EOD&gt;   Here's how to display some text&lt;BR /&gt;without using "echo" commands.&lt;BR /&gt;&lt;BR /&gt;It even does multiple      spaces&lt;BR /&gt;and special characters, like&lt;BR /&gt;      (  )  &amp;lt;  &amp;gt;  |  \  ;  $  "  '&lt;BR /&gt;(without using quotation marks or&lt;BR /&gt;apostrophes).&lt;BR /&gt;&lt;BR /&gt;Begin input section...&lt;BR /&gt;EOD&lt;BR /&gt;&lt;BR /&gt;ans_ok=0&lt;BR /&gt;while [ ${ans_ok} -eq 0 ] ; do&lt;BR /&gt;    echo -n "   Type \"fred\" (or don't -- \"quit\" to quit): "&lt;BR /&gt;    read line&lt;BR /&gt;    if [ "${line}" = 'fred' ] ; then&lt;BR /&gt;        ans_ok=1&lt;BR /&gt;    else&lt;BR /&gt;        l1=` echo "${line}" | cut -c 1 `&lt;BR /&gt;        if [ "${l1}" = 'q' -o "${l1}" = 'Q' ] ; then&lt;BR /&gt;            ans_ok=-1&lt;BR /&gt;        fi&lt;BR /&gt;    fi&lt;BR /&gt;    if [ ${ans_ok} -eq 0 ] ; then&lt;BR /&gt;        echo "      Invalid response: &amp;gt;${line}&amp;lt;.  Try again..."&lt;BR /&gt;    fi&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;echo "   ans_ok = ${ans_ok}, line: &amp;gt;${line}&amp;lt;."&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;It's probably not ideal, but it does a few&lt;BR /&gt;things properly.</description>
      <pubDate>Fri, 23 Oct 2009 05:05:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/improving-an-existing-script/m-p/4519711#M61916</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2009-10-23T05:05:34Z</dc:date>
    </item>
    <item>
      <title>Re: Improving an existing script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/improving-an-existing-script/m-p/4519712#M61917</link>
      <description>&lt;!--!*#--&gt;A particularly common "echo" hazard:&lt;BR /&gt;&lt;BR /&gt;bash$ cat echo1.sh&lt;BR /&gt;#!/bin/sh&lt;BR /&gt;&lt;BR /&gt;echo "This'll work."&lt;BR /&gt;echo This won't work.&lt;BR /&gt;echo "This would've worked."&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Unless you're a particular member of the crew&lt;BR /&gt;of the starship Enterprise, unquoted "echo"&lt;BR /&gt;text can cause problems, even for text which&lt;BR /&gt;is pretty ordinary (for most folks).</description>
      <pubDate>Fri, 23 Oct 2009 14:29:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/improving-an-existing-script/m-p/4519712#M61917</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2009-10-23T14:29:53Z</dc:date>
    </item>
    <item>
      <title>Re: Improving an existing script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/improving-an-existing-script/m-p/4519713#M61918</link>
      <description>I am going through the process of implementing your suggestions, and this posting is a response to the questions of your previous posting:&lt;BR /&gt;&lt;BR /&gt;The reason I copy the ps files from the original directory to the temporary one is due to the original location being an NFS mount and the conversion of the ps files over the network to that location was taking prohibitively long to complete. Copying the files to a local directory, running the ps2pdf command there, and then copying them back proved to be better in regards to performance. The removing of the files from the temporary location is simply a house-keeping measure. &lt;BR /&gt;&lt;BR /&gt;The directories themselves do not have any spaces within their names, and that is due to the application being used that creates them.&lt;BR /&gt;&lt;BR /&gt;I will double-check my syntax with the echo statements, and accordingly modify them.&lt;BR /&gt;&lt;BR /&gt;Thank-you for your help.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 23 Oct 2009 15:15:58 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/improving-an-existing-script/m-p/4519713#M61918</guid>
      <dc:creator>Andrew Kaplan</dc:creator>
      <dc:date>2009-10-23T15:15:58Z</dc:date>
    </item>
    <item>
      <title>Re: Improving an existing script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/improving-an-existing-script/m-p/4519714#M61919</link>
      <description>&lt;!--!*#--&gt;&amp;gt; [...] conversion of the ps files over the&lt;BR /&gt;&amp;gt; network to that location was taking&lt;BR /&gt;&amp;gt; prohibitively long [...]&lt;BR /&gt;&lt;BR /&gt;Really?  You measured this carefully?&lt;BR /&gt;Including the copy operations?  Both ends?&lt;BR /&gt;&lt;BR /&gt;Knowing nothing about your "ps2pdf" program,&lt;BR /&gt;I can imagine that it might make multiple&lt;BR /&gt;passes through the input file, so, if your&lt;BR /&gt;network really is a bottleneck, then copying&lt;BR /&gt;the input file (once) to a local work file&lt;BR /&gt;might be helpful, but it's harder to imagine&lt;BR /&gt;that it writes the output file more than&lt;BR /&gt;once, so it's less obvious (to me) that&lt;BR /&gt;writing to a local file and then copying that&lt;BR /&gt;over the network would buy you anything.&lt;BR /&gt;&lt;BR /&gt;&amp;gt; The removing of the files from the&lt;BR /&gt;&amp;gt; temporary location is simply a&lt;BR /&gt;&amp;gt; house-keeping measure.&lt;BR /&gt;&lt;BR /&gt;If you actually need temporary files, then&lt;BR /&gt;deleting them when you're done is good.  I&lt;BR /&gt;apparently got confused between ps and pdf,&lt;BR /&gt;and thought that you were copying the ps&lt;BR /&gt;files back to the source, not only the pdf&lt;BR /&gt;files.  (Probably looking at the wrong "cp"&lt;BR /&gt;command.  Trust no one, I always say.)&lt;BR /&gt;&lt;BR /&gt;&amp;gt; The directories themselves do not have any&lt;BR /&gt;&amp;gt; spaces within their names, [...]&lt;BR /&gt;&lt;BR /&gt;Still, quotation marks are pretty cheap, and&lt;BR /&gt;your script might live longer than the&lt;BR /&gt;current conditions.  Also, writing robust&lt;BR /&gt;code can become a habit, but that generally&lt;BR /&gt;requires doing it.</description>
      <pubDate>Fri, 23 Oct 2009 18:47:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/improving-an-existing-script/m-p/4519714#M61919</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2009-10-23T18:47:00Z</dc:date>
    </item>
    <item>
      <title>Re: Improving an existing script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/improving-an-existing-script/m-p/4519715#M61920</link>
      <description>I did some further testing, and the code shown below is what I inserted into the script:&lt;BR /&gt;&lt;BR /&gt;##########################################&lt;BR /&gt;read -p "Is the directory name that was entered spelled correctly &lt;YES&gt;"&lt;BR /&gt;if [ $REPLY = "no" ]; then&lt;BR /&gt;echo Reenter the patient directory name.&lt;BR /&gt;exit&lt;BR /&gt;fi&lt;BR /&gt;##########################################&lt;BR /&gt;&lt;BR /&gt;This addition appears to work as far as the users are concerned. &lt;BR /&gt;&lt;BR /&gt;Regarding your question about testing it at both ends: The test that I did was as follows, a patient directory was chosen, and the ps2pdf command was first run over the NFS mount. The calculated time for completion was approximately fifteen minutes. The generated pdf files were then deleted, and the same command was run after the .ps files were copied to a local directory, converted to pdf format, and then copied back to the source. The approximate time for completion was about five minutes. &lt;BR /&gt;&lt;/YES&gt;</description>
      <pubDate>Fri, 23 Oct 2009 19:19:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/improving-an-existing-script/m-p/4519715#M61920</guid>
      <dc:creator>Andrew Kaplan</dc:creator>
      <dc:date>2009-10-23T19:19:30Z</dc:date>
    </item>
    <item>
      <title>Re: Improving an existing script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/improving-an-existing-script/m-p/4519716#M61921</link>
      <description>&lt;!--!*#--&gt;&amp;gt; The test that I did was as follows [...]&lt;BR /&gt;&lt;BR /&gt;And what happens if you make a local copy of&lt;BR /&gt;the ".ps" file, but create the output file&lt;BR /&gt;directly on the remote file system?&lt;BR /&gt;&lt;BR /&gt;Or the other way around?&lt;BR /&gt;&lt;BR /&gt;And those with-local-copy times include the&lt;BR /&gt;copying?&lt;BR /&gt;&lt;BR /&gt;&amp;gt; read -p "Is the directory name that was entered spelled correctly &lt;YES&gt;"&lt;BR /&gt;&amp;gt; if [ $REPLY = "no" ]; then&lt;BR /&gt;&lt;BR /&gt;I'm sure glad that I don't need to use this&lt;BR /&gt;thing.  In my neighborhood, people would get&lt;BR /&gt;highly annoyed in they were compelled to type&lt;BR /&gt;"no", not "n", "N", "No", "nO", "NO", "NO!",&lt;BR /&gt;or so on.  What happens if the user spells&lt;BR /&gt;"no" incorrectly?  Does it make more sense to&lt;BR /&gt;test for "yes" or "no"?  (If you think that&lt;BR /&gt;there's no difference, then think again.)&lt;BR /&gt;What should happen if the user responds to a&lt;BR /&gt;yes-no question with, say, "Fred"?&lt;BR /&gt;&lt;BR /&gt;In most places, questions like this have a&lt;BR /&gt;default answer, so the prompt might look&lt;BR /&gt;like, say:&lt;BR /&gt;   Question (Y/N [Y])?&lt;BR /&gt;or&lt;BR /&gt;   Question (Y/n)?&lt;BR /&gt;and the program would interpret a null&lt;BR /&gt;response as "Yes".&lt;BR /&gt;&lt;BR /&gt;&amp;gt; exit&lt;BR /&gt;&lt;BR /&gt;What, asking again is too complex?  Sheesh.&lt;BR /&gt;&lt;BR /&gt;Did you try running that example script I&lt;BR /&gt;offered?  Did you look at what it does?&lt;BR /&gt;&lt;BR /&gt;Your users (or management) must be&lt;BR /&gt;exceptionally tolerant.&lt;/YES&gt;</description>
      <pubDate>Fri, 23 Oct 2009 21:47:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/improving-an-existing-script/m-p/4519716#M61921</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2009-10-23T21:47:29Z</dc:date>
    </item>
  </channel>
</rss>

