- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: error in script
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2005 03:12 AM
09-06-2005 03:12 AM
./backupcdr: line 49: syntax error: unexpected end of file
please help!!
#!/bin/bash
cd /home/test
#
filename=/home/backup.`date '+%d.%m.%Y.%k.%M.%S'`.tar
indexfile=/home/backup.`date '+%d.%m.%Y.%k.%M.%S'`.txt
ls -l /home/test >$indexfile
mkdir -p /home/backup-tijd
for file in $(ls *.test); do
mv ${file} /home/backup-tijd
done
cd /home/backup-tijd
tar cvf $filename .
if [ $? -ne 0 ];
then echo "tar failed"
exit 0
else
echo “tar ok”
fi
gzip $filename
if [ $? -ne 0 ];
then echo "gzip failed"
exit 1
else
echo “gzip ok”
if
exit 0
exit 1
Solved! Go to Solution.
- Tags:
- bash
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2005 03:22 AM
09-06-2005 03:22 AM
Re: error in script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2005 05:35 AM
09-06-2005 05:35 AM
Re: error in script
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.
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2005 05:54 AM
09-06-2005 05:54 AM
Re: error in script
UNIX because I majored in cryptology...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2005 05:57 AM
09-06-2005 05:57 AM
Re: error in script
if [ -s $( ls ) ]
then
tar cvf $filename *
gzip $filename
exit 0
else
echo "No file created"
exit 1
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2005 05:58 AM
09-06-2005 05:58 AM
Re: error in script
Hi,
I would suggest some modifications (last part of the script).
cd /home/backup-tijd
if [ -s $( ls ) ]
then
tar cvf $filename *
gzip $filename
exit 0
else
echo "No file created"
exit 1
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2005 06:13 AM
09-06-2005 06:13 AM
Re: error in script
regards!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2005 06:17 AM
09-06-2005 06:17 AM
Re: error in script
wc -l ./backupcdr
it means that there is a mismatching if-then-else or for/while/until-do-done construct, which reinforces the incorrect if/fi.
UNIX because I majored in cryptology...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2005 02:46 AM
09-07-2005 02:46 AM
Re: error in script
I want to use the exit to exit the script doesnâ t it work that way? Is the exit 0 only the error output?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2005 02:57 AM
09-07-2005 02:57 AM
Re: error in script
Also, double-check all your quotation and backtick marks. I've seen this error caused by having unmached quotes.
Regards,
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2005 03:12 AM
09-07-2005 03:12 AM
Re: error in script
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.
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.
So you will get always 0 or 1 as return values irrespective of the actual return from the loops.
- Tags:
- exit status
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2005 03:35 AM
09-07-2005 03:35 AM
Solutionexit 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.
In my opinion, your script could be better of with this type of struct:
#!/bin/bash
cd /home/test
filename=/home/backup.`date '+%d.%m.%Y.%k.%M.%S'`.tar
indexfile=/home/backup.`date '+%d.%m.%Y.%k.%M.%S'`.txt
ls -l /home/test >$indexfile
mkdir -p /home/backup-tijd
for file in $(ls *.test); do
mv ${file} /home/backup-tijd
done
cd /home/backup-tijd
tar cvf $filename .
if [ $? -ne 0 ];
then echo "tar failed"
exit 1
else
echo "tar ok"
fi
gzip $filename
if [ $? -ne 0 ];
then echo "gzip failed"
exit 2
else
echo "gzip ok"
fi
echo "all procedure completed successfully"
exit 0
so, according to the above, if you test the exit code of the script, you can tell the user where exactly the failure was.
UNIX because I majored in cryptology...