<?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 for tar &amp;amp; compressing files in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/script-for-tar-amp-compressing-files/m-p/4372530#M347495</link>
    <description>Thanks, i am not good in scripting.&lt;BR /&gt;Does the below script look fine.&lt;BR /&gt;&lt;BR /&gt;cd /tmp&lt;BR /&gt;val1=find /tmp -mtime +10&lt;BR /&gt;if [$? -eg 0 ]&lt;BR /&gt;then&lt;BR /&gt;tar cvf $val1 | gzip *.tar&lt;BR /&gt;else&lt;BR /&gt;echo "No files older than 10 days"&lt;BR /&gt;val3=find /tmp -name "*.gz" -mtime +10&lt;BR /&gt;echo " List of tar files $val3 "&lt;BR /&gt;if [$? -eg 0 ]&lt;BR /&gt;then&lt;BR /&gt;rm *.gz&lt;BR /&gt;fi&lt;BR /&gt;fi&lt;BR /&gt;</description>
    <pubDate>Thu, 05 Mar 2009 15:27:12 GMT</pubDate>
    <dc:creator>mjos</dc:creator>
    <dc:date>2009-03-05T15:27:12Z</dc:date>
    <item>
      <title>Script for tar &amp; compressing files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-for-tar-amp-compressing-files/m-p/4372528#M347493</link>
      <description>Hi,&lt;BR /&gt;need help with tar &amp;amp; compress all files in a folder older than 10 days. Then the script should delete the gz files that are older than 10 days.</description>
      <pubDate>Thu, 05 Mar 2009 14:52:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-for-tar-amp-compressing-files/m-p/4372528#M347493</guid>
      <dc:creator>mjos</dc:creator>
      <dc:date>2009-03-05T14:52:46Z</dc:date>
    </item>
    <item>
      <title>Re: Script for tar &amp; compressing files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-for-tar-amp-compressing-files/m-p/4372529#M347494</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;What have you tried?  Use 'find' to find files ( -type f ) older than 10-days ( -mtime +10 ).  &lt;BR /&gt;&lt;BR /&gt;Collect the filenames output and use this list as a argument to 'tar'.  Then 'gzip' the tarball.  When done, use 'find' again looking for files named "*.gz" that are older than 10-days ( -name "*.gz* -mtime +10 ) and remove them ( '-exec rm {} +' ).&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Thu, 05 Mar 2009 15:01:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-for-tar-amp-compressing-files/m-p/4372529#M347494</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-03-05T15:01:24Z</dc:date>
    </item>
    <item>
      <title>Re: Script for tar &amp; compressing files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-for-tar-amp-compressing-files/m-p/4372530#M347495</link>
      <description>Thanks, i am not good in scripting.&lt;BR /&gt;Does the below script look fine.&lt;BR /&gt;&lt;BR /&gt;cd /tmp&lt;BR /&gt;val1=find /tmp -mtime +10&lt;BR /&gt;if [$? -eg 0 ]&lt;BR /&gt;then&lt;BR /&gt;tar cvf $val1 | gzip *.tar&lt;BR /&gt;else&lt;BR /&gt;echo "No files older than 10 days"&lt;BR /&gt;val3=find /tmp -name "*.gz" -mtime +10&lt;BR /&gt;echo " List of tar files $val3 "&lt;BR /&gt;if [$? -eg 0 ]&lt;BR /&gt;then&lt;BR /&gt;rm *.gz&lt;BR /&gt;fi&lt;BR /&gt;fi&lt;BR /&gt;</description>
      <pubDate>Thu, 05 Mar 2009 15:27:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-for-tar-amp-compressing-files/m-p/4372530#M347495</guid>
      <dc:creator>mjos</dc:creator>
      <dc:date>2009-03-05T15:27:12Z</dc:date>
    </item>
    <item>
      <title>Re: Script for tar &amp; compressing files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-for-tar-amp-compressing-files/m-p/4372531#M347496</link>
      <description>&lt;!--!*#--&gt;&amp;gt; [...] Then 'gzip' the tarball. [...]&lt;BR /&gt;&lt;BR /&gt;tar [...] | gzip&lt;BR /&gt;&lt;BR /&gt;No need for a (temporary) "tarball" file.</description>
      <pubDate>Thu, 05 Mar 2009 15:27:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-for-tar-amp-compressing-files/m-p/4372531#M347496</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2009-03-05T15:27:24Z</dc:date>
    </item>
    <item>
      <title>Re: Script for tar &amp; compressing files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-for-tar-amp-compressing-files/m-p/4372532#M347497</link>
      <description>&lt;!--!*#--&gt;Hi:&lt;BR /&gt;&lt;BR /&gt;OK, you have the general idea.  Try this:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;cd /tmp || exit 1&lt;BR /&gt;FILES=$(find . -type f -mtime +10)&lt;BR /&gt;[ -z "${FILES}" ] &amp;amp;&amp;amp; { echo "no files older than 10-days"; exit 1; }&lt;BR /&gt;tar -cvf - ${FILES} | gzip - &amp;gt; /var/tmp/myarch.gz&lt;BR /&gt;find . -type f -name "*.gz" -mtime +10 -exec rm {} +&lt;BR /&gt;exit 0&lt;BR /&gt;&lt;BR /&gt;...notice that we use a pipe to 'gzip' as Steven suggested to eliminate an intermediate file.&lt;BR /&gt;&lt;BR /&gt;Noitce too, that the proper word in UNIX is "directory", not "folder" :-)&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 05 Mar 2009 15:46:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-for-tar-amp-compressing-files/m-p/4372532#M347497</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-03-05T15:46:17Z</dc:date>
    </item>
    <item>
      <title>Re: Script for tar &amp; compressing files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-for-tar-amp-compressing-files/m-p/4372533#M347498</link>
      <description>thanks, if the gz file already exists then, it should create a new gz file. How do I do that in the script.</description>
      <pubDate>Thu, 05 Mar 2009 18:55:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-for-tar-amp-compressing-files/m-p/4372533#M347498</guid>
      <dc:creator>mjos</dc:creator>
      <dc:date>2009-03-05T18:55:03Z</dc:date>
    </item>
    <item>
      <title>Re: Script for tar &amp; compressing files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-for-tar-amp-compressing-files/m-p/4372534#M347499</link>
      <description>&lt;!--!*#--&gt;Hi:&lt;BR /&gt;&lt;BR /&gt;&amp;gt; if the gz file already exists then, it should create a new gz file. How do I do that in the script.&lt;BR /&gt;&lt;BR /&gt;You don't need to do anything.  The redirection of the 'gzip' STDOUT to the file specified causes the shell to clobber any file already there.&lt;BR /&gt;&lt;BR /&gt;If you prefer, 'rm' the final output file when the script begins:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;set -u&lt;BR /&gt;GZARCH=/var/tmp/myarch.gz&lt;BR /&gt;rm -f "${GZARCH}"&lt;BR /&gt;cd /tmp/dummydir || exit 1&lt;BR /&gt;FILES=$(find . -type f -mtime +10)&lt;BR /&gt;[ -z "${FILES}" ] &amp;amp;&amp;amp; { echo "no files older than 10-days"; exit 1; }&lt;BR /&gt;tar -cvf - ${FILES} | gzip - &amp;gt; ${GZARCH}&lt;BR /&gt;find . -type f -name "*.gz" -mtime +10 -exec rm {} +&lt;BR /&gt;exit 0&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Thu, 05 Mar 2009 19:04:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-for-tar-amp-compressing-files/m-p/4372534#M347499</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-03-05T19:04:43Z</dc:date>
    </item>
    <item>
      <title>Re: Script for tar &amp; compressing files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-for-tar-amp-compressing-files/m-p/4372535#M347500</link>
      <description>Thanks James.&lt;BR /&gt;I dont want to delete all gz files. I only want to delete only those gz files which are older than 10 days. And when I run the script, if there is a gz file which is not older than 10 days, then the script should check &amp;amp; create another gz file without deleted the old gz file.</description>
      <pubDate>Thu, 05 Mar 2009 19:11:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-for-tar-amp-compressing-files/m-p/4372535#M347500</guid>
      <dc:creator>mjos</dc:creator>
      <dc:date>2009-03-05T19:11:07Z</dc:date>
    </item>
    <item>
      <title>Re: Script for tar &amp; compressing files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-for-tar-amp-compressing-files/m-p/4372536#M347501</link>
      <description>&lt;!--!*#--&gt;Hi (again):&lt;BR /&gt;&lt;BR /&gt;&amp;gt; I dont want to delete all gz files. I only want to delete only those gz files which are older than 10 days. And when I run the script, if there is a gz file which is not older than 10 days, then the script should check &amp;amp; create another gz file without deleted the old gz file.&lt;BR /&gt;&lt;BR /&gt;Then consider this:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;set -u&lt;BR /&gt;SEARCH=/tmp&lt;BR /&gt;GZDIR=/var/tmp&lt;BR /&gt;GZFILE=${GZDIR}/myarch_$(date +%Y%m%d).gz&lt;BR /&gt;cd ${SEARCH} || exit 1&lt;BR /&gt;FILES=$(find . -type f -mtime +10)&lt;BR /&gt;[ -z "${FILES}" ] &amp;amp;&amp;amp; { echo "no files older than 10-days"; exit 1; }&lt;BR /&gt;tar -cvf - ${FILES} | gzip - &amp;gt; ${GZFILE}&lt;BR /&gt;find ${GZDIR} -type f -name "*.gz" -mtime +10 -exec rm {} +&lt;BR /&gt;rm ${FILES} #...to remove what you archived...&lt;BR /&gt;exit 0&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 05 Mar 2009 19:25:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-for-tar-amp-compressing-files/m-p/4372536#M347501</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-03-05T19:25:47Z</dc:date>
    </item>
    <item>
      <title>Re: Script for tar &amp; compressing files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-for-tar-amp-compressing-files/m-p/4372537#M347502</link>
      <description>Thanks a lot James.&lt;BR /&gt;Appreciate your help. I have assaigned points to you.</description>
      <pubDate>Thu, 05 Mar 2009 19:41:33 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-for-tar-amp-compressing-files/m-p/4372537#M347502</guid>
      <dc:creator>mjos</dc:creator>
      <dc:date>2009-03-05T19:41:33Z</dc:date>
    </item>
  </channel>
</rss>

