<?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: error in script in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/error-in-script/m-p/3619680#M104673</link>
    <description>The shell should be able to detect an unmatched if and produce diagnostic output saying that "if is not matched". This seems like its a problem with your tar or gzip. Could you attach your shell script instead of pasting it.&lt;BR /&gt;&lt;BR /&gt;regards!</description>
    <pubDate>Tue, 06 Sep 2005 13:13:40 GMT</pubDate>
    <dc:creator>Sandman!</dc:creator>
    <dc:date>2005-09-06T13:13:40Z</dc:date>
    <item>
      <title>error in script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/error-in-script/m-p/3619674#M104667</link>
      <description>What’s wrong with this script i get the error:  &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;./backupcdr: line 49: syntax error: unexpected end of file&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;please help!!&lt;BR /&gt;&lt;BR /&gt;#!/bin/bash&lt;BR /&gt;&lt;BR /&gt;cd /home/test&lt;BR /&gt;#&lt;BR /&gt;filename=/home/backup.`date '+%d.%m.%Y.%k.%M.%S'`.tar&lt;BR /&gt;indexfile=/home/backup.`date '+%d.%m.%Y.%k.%M.%S'`.txt&lt;BR /&gt;&lt;BR /&gt;ls -l /home/test &amp;gt;$indexfile&lt;BR /&gt;&lt;BR /&gt;mkdir -p /home/backup-tijd&lt;BR /&gt;&lt;BR /&gt;for file in $(ls *.test); do&lt;BR /&gt;mv ${file} /home/backup-tijd&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;cd /home/backup-tijd&lt;BR /&gt;        tar cvf $filename .&lt;BR /&gt;        if [ $? -ne 0 ];&lt;BR /&gt;then echo "tar failed"&lt;BR /&gt;exit 0&lt;BR /&gt;&lt;BR /&gt;else&lt;BR /&gt;echo “tar ok”&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;  gzip $filename&lt;BR /&gt;if [ $? -ne 0 ];&lt;BR /&gt;then echo "gzip failed"&lt;BR /&gt;exit 1&lt;BR /&gt;else&lt;BR /&gt;echo “gzip ok”&lt;BR /&gt;if&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;exit 0&lt;BR /&gt;exit 1&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 06 Sep 2005 10:12:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/error-in-script/m-p/3619674#M104667</guid>
      <dc:creator>mick001</dc:creator>
      <dc:date>2005-09-06T10:12:50Z</dc:date>
    </item>
    <item>
      <title>Re: error in script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/error-in-script/m-p/3619675#M104668</link>
      <description>In the last if-then-else loop you should put fi instead of if . Secondly you can have only one exit statement at the end of the script. I guess you are expecting exit 0 there. Remove the exit 1 from the script.&lt;BR /&gt;</description>
      <pubDate>Tue, 06 Sep 2005 10:22:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/error-in-script/m-p/3619675#M104668</guid>
      <dc:creator>Sameer_Nirmal</dc:creator>
      <dc:date>2005-09-06T10:22:43Z</dc:date>
    </item>
    <item>
      <title>Re: error in script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/error-in-script/m-p/3619676#M104669</link>
      <description>I have to agree with Sameer.&lt;BR /&gt;&lt;BR /&gt;The if needs to be a fi at the end of your script.  Also to re-iterate, there is no need for exit 0, exit 1.&lt;BR /&gt;&lt;BR /&gt;The exit 0 signafies that the script has finished with no errors.  The exit 1 signafies that the script has exited with an error.  I see in your script that you have echo "tar failed", then right after that you have exit 0.  That should be an exit 1 to signify that there was an error.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 06 Sep 2005 12:35:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/error-in-script/m-p/3619676#M104669</guid>
      <dc:creator>Sheriff Andy</dc:creator>
      <dc:date>2005-09-06T12:35:46Z</dc:date>
    </item>
    <item>
      <title>Re: error in script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/error-in-script/m-p/3619677#M104670</link>
      <description>Even though the accidental interchange of "if" with "fi" seems to be the problem here, the characters around "tar ok" and "gzip ok", being non-printable, may cause you headaches in the long run. Fancy screen output is nice I am sure but function should be your primary concern. Just my 2 cents</description>
      <pubDate>Tue, 06 Sep 2005 12:54:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/error-in-script/m-p/3619677#M104670</guid>
      <dc:creator>Mel Burslan</dc:creator>
      <dc:date>2005-09-06T12:54:11Z</dc:date>
    </item>
    <item>
      <title>Re: error in script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/error-in-script/m-p/3619678#M104671</link>
      <description>cd /home/backup-tijd&lt;BR /&gt;&lt;BR /&gt;if [ -s $( ls ) ]&lt;BR /&gt;then&lt;BR /&gt;tar cvf $filename *&lt;BR /&gt;gzip $filename&lt;BR /&gt;exit 0&lt;BR /&gt;else&lt;BR /&gt;echo "No file created"&lt;BR /&gt;exit 1&lt;BR /&gt;fi&lt;BR /&gt;</description>
      <pubDate>Tue, 06 Sep 2005 12:57:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/error-in-script/m-p/3619678#M104671</guid>
      <dc:creator>Leif Halvarsson_2</dc:creator>
      <dc:date>2005-09-06T12:57:57Z</dc:date>
    </item>
    <item>
      <title>Re: error in script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/error-in-script/m-p/3619679#M104672</link>
      <description>&lt;BR /&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;I would suggest some modifications (last part of the script).&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;cd /home/backup-tijd&lt;BR /&gt;&lt;BR /&gt;if [ -s $( ls ) ]&lt;BR /&gt;then&lt;BR /&gt;tar cvf $filename *&lt;BR /&gt;gzip $filename&lt;BR /&gt;exit 0&lt;BR /&gt;else&lt;BR /&gt;echo "No file created"&lt;BR /&gt;exit 1&lt;BR /&gt;fi&lt;BR /&gt;</description>
      <pubDate>Tue, 06 Sep 2005 12:58:58 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/error-in-script/m-p/3619679#M104672</guid>
      <dc:creator>Leif Halvarsson_2</dc:creator>
      <dc:date>2005-09-06T12:58:58Z</dc:date>
    </item>
    <item>
      <title>Re: error in script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/error-in-script/m-p/3619680#M104673</link>
      <description>The shell should be able to detect an unmatched if and produce diagnostic output saying that "if is not matched". This seems like its a problem with your tar or gzip. Could you attach your shell script instead of pasting it.&lt;BR /&gt;&lt;BR /&gt;regards!</description>
      <pubDate>Tue, 06 Sep 2005 13:13:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/error-in-script/m-p/3619680#M104673</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2005-09-06T13:13:40Z</dc:date>
    </item>
    <item>
      <title>Re: error in script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/error-in-script/m-p/3619681#M104674</link>
      <description>also, the script you have posted, if copied verbatim from a terminal screen, has only 37 lines. In order to get a complaint about line 49, you must have gobs of blank lines at the end and if the number of lines in this script is actually showing up as 49, which you can check by &lt;BR /&gt;&lt;BR /&gt;wc -l ./backupcdr&lt;BR /&gt;&lt;BR /&gt;it means that there is a mismatching if-then-else or for/while/until-do-done construct, which reinforces the incorrect if/fi.</description>
      <pubDate>Tue, 06 Sep 2005 13:17:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/error-in-script/m-p/3619681#M104674</guid>
      <dc:creator>Mel Burslan</dc:creator>
      <dc:date>2005-09-06T13:17:57Z</dc:date>
    </item>
    <item>
      <title>Re: error in script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/error-in-script/m-p/3619682#M104675</link>
      <description>I didnâ  t see the fault thanks!!&lt;BR /&gt;&lt;BR /&gt;I want to use the exit to exit the script doesnâ  t it work that way? Is the exit 0 only the error output?&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;</description>
      <pubDate>Wed, 07 Sep 2005 09:46:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/error-in-script/m-p/3619682#M104675</guid>
      <dc:creator>mick001</dc:creator>
      <dc:date>2005-09-07T09:46:10Z</dc:date>
    </item>
    <item>
      <title>Re: error in script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/error-in-script/m-p/3619683#M104676</link>
      <description>Mick,&lt;BR /&gt;&lt;BR /&gt;Also, double-check all your quotation and backtick marks.  I've seen this error caused by having unmached quotes.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Mark</description>
      <pubDate>Wed, 07 Sep 2005 09:57:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/error-in-script/m-p/3619683#M104676</guid>
      <dc:creator>Mark Ellzey</dc:creator>
      <dc:date>2005-09-07T09:57:11Z</dc:date>
    </item>
    <item>
      <title>Re: error in script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/error-in-script/m-p/3619684#M104677</link>
      <description>You are trying to have a exit status in each &lt;BR /&gt;of those loops ( tar and gzip). In the first tar loop, if the tar failed, you are supposed to have exit 1 and not exit 0 . Then put exit 0 after echo "tar ok" . If successful return of any status should be exit 0 becuase shell understand it that way.&lt;BR /&gt;If you are taking care of exit status return at each loop, you don't need to have exit at the end. Those last exit will be always the return values for any condition of any loop.&lt;BR /&gt;So you will get always 0 or 1 as return values irrespective of the actual return from the loops.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 07 Sep 2005 10:12:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/error-in-script/m-p/3619684#M104677</guid>
      <dc:creator>Sameer_Nirmal</dc:creator>
      <dc:date>2005-09-07T10:12:06Z</dc:date>
    </item>
    <item>
      <title>Re: error in script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/error-in-script/m-p/3619685#M104678</link>
      <description>Mick,&lt;BR /&gt;&lt;BR /&gt;exit 0 is not an error code let alone being the only one. Au contraire, exit 0 is the exit code for error-free completion of an executable as a convention but you can call successful completion as exit code 5 and trap for this one if your heart desires so. It is not an absolute  requirement as long as you know what you are doing.&lt;BR /&gt;&lt;BR /&gt;In my opinion, your script could be better of with this type of struct:&lt;BR /&gt;&lt;BR /&gt;#!/bin/bash&lt;BR /&gt;cd /home/test&lt;BR /&gt;&lt;BR /&gt;filename=/home/backup.`date '+%d.%m.%Y.%k.%M.%S'`.tar&lt;BR /&gt;indexfile=/home/backup.`date '+%d.%m.%Y.%k.%M.%S'`.txt&lt;BR /&gt;&lt;BR /&gt;ls -l /home/test &amp;gt;$indexfile&lt;BR /&gt;&lt;BR /&gt;mkdir -p /home/backup-tijd&lt;BR /&gt;&lt;BR /&gt;for file in $(ls *.test); do&lt;BR /&gt;mv ${file} /home/backup-tijd&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;cd /home/backup-tijd&lt;BR /&gt;tar cvf $filename .&lt;BR /&gt;&lt;BR /&gt;if [ $? -ne 0 ];&lt;BR /&gt;then echo "tar failed"&lt;BR /&gt;exit 1&lt;BR /&gt;else&lt;BR /&gt;echo "tar ok"&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;gzip $filename&lt;BR /&gt;if [ $? -ne 0 ];&lt;BR /&gt;then echo "gzip failed"&lt;BR /&gt;exit 2&lt;BR /&gt;else&lt;BR /&gt;echo "gzip ok"&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;echo "all procedure completed successfully"&lt;BR /&gt;exit 0&lt;BR /&gt;&lt;BR /&gt;so, according to the above, if you test the exit code of the script, you can tell the user where exactly the failure was.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 07 Sep 2005 10:35:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/error-in-script/m-p/3619685#M104678</guid>
      <dc:creator>Mel Burslan</dc:creator>
      <dc:date>2005-09-07T10:35:34Z</dc:date>
    </item>
  </channel>
</rss>

