<?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: script question in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/script-question/m-p/2653445#M921759</link>
    <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I need to make one correction to my posting above regarding your gzip statement. gzip is used for compressing individual files and not for archiving. If you are specifically talking about archiving (tar) and compressing the tar file (gzip) later, then you should use a combination of tar and gzip:&lt;BR /&gt;&lt;BR /&gt;tar cvf - /home/* | gzip &amp;gt; /home/home.tar.gz &amp;gt; ${DIR}/${LOGFILE} 2&amp;gt;&amp;amp;1&lt;BR /&gt;&lt;BR /&gt;Hope this helps. Regards.&lt;BR /&gt;&lt;BR /&gt;Steven Sim Kok Leong</description>
    <pubDate>Sun, 27 Jan 2002 00:15:34 GMT</pubDate>
    <dc:creator>Steven Sim Kok Leong</dc:creator>
    <dc:date>2002-01-27T00:15:34Z</dc:date>
    <item>
      <title>script question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-question/m-p/2653435#M921749</link>
      <description>Hello to everyone. This is my first time on this site and I am also very new to Unix. Here is my first question. I am writing my first script and am getting a error message for line 17. My script is suppossed to copy the logfile to .date. It will the zero the file. It will then gzip the .date file. Last thing it will do is remove .date files more than 30 days old. Please let meknow what I'm doing wrong here.&lt;BR /&gt;&lt;BR /&gt;OLD="14"&lt;BR /&gt;TODAY=$(date +%Y%m%d)&lt;BR /&gt;&lt;BR /&gt;DIR="/test/test"&lt;BR /&gt;LOGFILE="test.log"&lt;BR /&gt;&lt;BR /&gt;log_file() {&lt;BR /&gt;&lt;BR /&gt;if [ -f ${DIR}/${LOGFILE} ]&lt;BR /&gt;then&lt;BR /&gt;cp -f ${DIR}/${LOGFILE} ${DIR}/${LOGFILE}.${TODAY}&lt;BR /&gt;cp /dev/null ${DIR/${LOGFILE}&lt;BR /&gt;gzip -f ${DIR}/${LOGFILE}.${TODAY}&lt;BR /&gt;&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;print "Checking for files older than $OLD old days old."&lt;BR /&gt;&lt;BR /&gt;print "Removing Files ..."&lt;BR /&gt;&lt;BR /&gt;find ${DIR} -name "${LOGFILE}.*" -mtime +$OLD -exec rm -f {} \;&lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt; Thanks for the time and help. &lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Sat, 26 Jan 2002 05:05:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-question/m-p/2653435#M921749</guid>
      <dc:creator>Jon Rios</dc:creator>
      <dc:date>2002-01-26T05:05:28Z</dc:date>
    </item>
    <item>
      <title>Re: script question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-question/m-p/2653436#M921750</link>
      <description>Try using echo instead of print.</description>
      <pubDate>Sat, 26 Jan 2002 05:16:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-question/m-p/2653436#M921750</guid>
      <dc:creator>Patrick Wallek</dc:creator>
      <dc:date>2002-01-26T05:16:43Z</dc:date>
    </item>
    <item>
      <title>Re: script question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-question/m-p/2653437#M921751</link>
      <description>Its complaining about THEN statement, right after the if statement. Please help.</description>
      <pubDate>Sat, 26 Jan 2002 05:19:58 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-question/m-p/2653437#M921751</guid>
      <dc:creator>Jon Rios</dc:creator>
      <dc:date>2002-01-26T05:19:58Z</dc:date>
    </item>
    <item>
      <title>Re: script question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-question/m-p/2653438#M921752</link>
      <description>Jon,&lt;BR /&gt;&lt;BR /&gt;Which line is line 17? And what was the error message?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;live free or die&lt;BR /&gt;harry</description>
      <pubDate>Sat, 26 Jan 2002 05:20:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-question/m-p/2653438#M921752</guid>
      <dc:creator>harry d brown jr</dc:creator>
      <dc:date>2002-01-26T05:20:43Z</dc:date>
    </item>
    <item>
      <title>Re: script question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-question/m-p/2653439#M921753</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;Replace "done" with "fi".&lt;BR /&gt;&lt;BR /&gt;if [ -f ${DIR}/${LOGFILE} ] &lt;BR /&gt;then &lt;BR /&gt;cp -f ${DIR}/${LOGFILE} ${DIR}/${LOGFILE}.${TODAY} &lt;BR /&gt;cp /dev/null ${DIR/${LOGFILE} &lt;BR /&gt;gzip -f ${DIR}/${LOGFILE}.${TODAY} &lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;Hope this helps. Regards.&lt;BR /&gt;&lt;BR /&gt;Steven Sim Kok Leong</description>
      <pubDate>Sat, 26 Jan 2002 05:27:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-question/m-p/2653439#M921753</guid>
      <dc:creator>Steven Sim Kok Leong</dc:creator>
      <dc:date>2002-01-26T05:27:01Z</dc:date>
    </item>
    <item>
      <title>Re: script question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-question/m-p/2653440#M921754</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;In case you are wondering what "fi" is, the loop structure for if is:&lt;BR /&gt;&lt;BR /&gt;if ... # your condition here&lt;BR /&gt;then&lt;BR /&gt;# your code here&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;You use done in a while loop:&lt;BR /&gt;&lt;BR /&gt;while ... # your condition here&lt;BR /&gt;do&lt;BR /&gt;  # your code here&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;Hope this explains it out for you. Regards.&lt;BR /&gt;&lt;BR /&gt;Steven Sim Kok Leong</description>
      <pubDate>Sat, 26 Jan 2002 05:41:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-question/m-p/2653440#M921754</guid>
      <dc:creator>Steven Sim Kok Leong</dc:creator>
      <dc:date>2002-01-26T05:41:37Z</dc:date>
    </item>
    <item>
      <title>Re: script question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-question/m-p/2653441#M921755</link>
      <description>Now I'm more confused then before. My syntax error is fixed now. I am able to execute my script. Bu t  when I go and look in my directory for a test.log.(date)O file, its not there. I even just tried the cp -p line in my script but its not doing anything. What is it that I have done wrong in my script. Thanks for your help and sorry for bugging anyone.</description>
      <pubDate>Sat, 26 Jan 2002 05:55:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-question/m-p/2653441#M921755</guid>
      <dc:creator>Jon Rios</dc:creator>
      <dc:date>2002-01-26T05:55:52Z</dc:date>
    </item>
    <item>
      <title>Re: script question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-question/m-p/2653442#M921756</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;There are a few issues with this script:&lt;BR /&gt;&lt;BR /&gt;1) log_file function is not called anywhere in the script. Preferably, it should be called after the function definition.&lt;BR /&gt;&lt;BR /&gt;2) There is a typo in your cp statement which explains why /test/test/test.log was not created. There is a missing closing parenthesis.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;&amp;gt; cp /dev/null ${DIR/${LOGFILE} &lt;BR /&gt;&lt;BR /&gt;It should be &lt;BR /&gt;&lt;BR /&gt;cp /dev/null ${DIR}/${LOGFILE}&lt;BR /&gt;&lt;BR /&gt;3) The gzip parameters are not correct. If you want your script to backup directories and files and keep the output log and errors during the archiving,&lt;BR /&gt;&lt;BR /&gt;Instead of&lt;BR /&gt;&lt;BR /&gt;&amp;gt;&amp;gt; gzip -f ${DIR}/${LOGFILE}.${TODAY} &lt;BR /&gt;&lt;BR /&gt;It should be&lt;BR /&gt;&lt;BR /&gt;gzip -f backup.gz list_of_dirs_and_files &amp;gt; ${DIR}/${LOGFILE} 2&amp;gt;&amp;amp;1&lt;BR /&gt;&lt;BR /&gt;The backup log will be /test/test/test.log&lt;BR /&gt;&lt;BR /&gt;Hope this helps. Regards.&lt;BR /&gt;&lt;BR /&gt;Steven Sim Kok Leong</description>
      <pubDate>Sat, 26 Jan 2002 11:28:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-question/m-p/2653442#M921756</guid>
      <dc:creator>Steven Sim Kok Leong</dc:creator>
      <dc:date>2002-01-26T11:28:16Z</dc:date>
    </item>
    <item>
      <title>Re: script question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-question/m-p/2653443#M921757</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;Btw, to call your log_file function, simply insert at the bottom of your script:&lt;BR /&gt;&lt;BR /&gt;log_file &lt;BR /&gt;&lt;BR /&gt;Hope this helps. Regards.&lt;BR /&gt;&lt;BR /&gt;Steven Sim Kok Leong</description>
      <pubDate>Sat, 26 Jan 2002 11:30:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-question/m-p/2653443#M921757</guid>
      <dc:creator>Steven Sim Kok Leong</dc:creator>
      <dc:date>2002-01-26T11:30:39Z</dc:date>
    </item>
    <item>
      <title>Re: script question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-question/m-p/2653444#M921758</link>
      <description>Hi Jon,&lt;BR /&gt;&lt;BR /&gt;You don't have to define your code as a function.  As Steven points out, a function must be called, it is not executed simply because it is defined.&lt;BR /&gt;&lt;BR /&gt;So, if this is simply a script you want to run from time to time, keep it simple by deleting the funciton definition lines:&lt;BR /&gt;log_file{} {&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;You wouldn't have the need for a statement to execute the code then.&lt;BR /&gt;&lt;BR /&gt;If you do intend to add more code to the script and want to call log_file multiple times, then you have done well to code the function.&lt;BR /&gt;&lt;BR /&gt;Darrell</description>
      <pubDate>Sat, 26 Jan 2002 15:18:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-question/m-p/2653444#M921758</guid>
      <dc:creator>Darrell Allen</dc:creator>
      <dc:date>2002-01-26T15:18:29Z</dc:date>
    </item>
    <item>
      <title>Re: script question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-question/m-p/2653445#M921759</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I need to make one correction to my posting above regarding your gzip statement. gzip is used for compressing individual files and not for archiving. If you are specifically talking about archiving (tar) and compressing the tar file (gzip) later, then you should use a combination of tar and gzip:&lt;BR /&gt;&lt;BR /&gt;tar cvf - /home/* | gzip &amp;gt; /home/home.tar.gz &amp;gt; ${DIR}/${LOGFILE} 2&amp;gt;&amp;amp;1&lt;BR /&gt;&lt;BR /&gt;Hope this helps. Regards.&lt;BR /&gt;&lt;BR /&gt;Steven Sim Kok Leong</description>
      <pubDate>Sun, 27 Jan 2002 00:15:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-question/m-p/2653445#M921759</guid>
      <dc:creator>Steven Sim Kok Leong</dc:creator>
      <dc:date>2002-01-27T00:15:34Z</dc:date>
    </item>
  </channel>
</rss>

