- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: exit 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
Discussions
Discussions
Forums
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
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-13-2005 01:20 AM
тАО09-13-2005 01:20 AM
The idea is that the script stop when the tar command fails. so that the files are not removed. did I do it correct?
Thanks
#!/bin/bash
set -v
cd /cdr1/pmc
#
filename=/cdr1/backup.cdr.`date '+%d.%m.%Y.%k.%M.%S'`.tar
indexfile=/cdr1/backup.cdr.`date '+%d.%m.%Y.%k.%M.%S'`.txt
ls -l /cdr1/pmc >$indexfile
mkdir -p /cdr1/backup-tijd
for file in $(ls *.BF); do
mv ${file} /cdr1/backup-tijd
done
cd /cdr1/backup-tijd
tar cvf $filename .
if [ $? -ne 0 ];
then
echo "tar failed"
exit
else
rm /cdr1/backup-tijd/*
rmdir /cdr1/backup-tijd/
fi
gzip $filename
if [ $? -ne 0 ];
then
echo "gzip-failed"
exit
else
touch gzip-ok
fi
exit
Solved! Go to Solution.
- Tags:
- exit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-13-2005 01:29 AM
тАО09-13-2005 01:29 AM
Re: exit in script!
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-13-2005 01:34 AM
тАО09-13-2005 01:34 AM
Re: exit in script!
seems good to me !
regards
pg
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-13-2005 01:36 AM
тАО09-13-2005 01:36 AM
Re: exit in script!
Like exit 3, exit 4, etc.
This will help you trace later on, as to from where has the code exited.
- Tags:
- exit status
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-13-2005 02:00 AM
тАО09-13-2005 02:00 AM
Re: exit in script!
Your handling of the return status from 'tar' and 'gzip' are fine.
I'll offer one unrelated suggestion.
The remove of the contents of the directory and then the directory itself can be coded with a recursive remove to handle both. More importantly, the use of the "*" wildcard which the shell will expand into a list of all of the files in the directory, could lead to an "argument list too long" error. [Of course, I'll grant that that was more a problem on older OS versions than newer ones where much larger argument space can be configured; but nevertheless, there is better form].
Thus, to remove your directory and its contents, simply do:
# cd /
# rm -r rm /cdr1/backup-tijd
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-13-2005 02:02 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-13-2005 02:58 AM
тАО09-13-2005 02:58 AM
Re: exit in script!
I would make changes similar to this:
typeset -i STAT=0
gzip ${filename}
STAT=${?} # save status in another variable
if [[ ${STAT} -ne 0 ]]
then
echo "gzip-failed; status ${STAT}." >&2
exit ${STAT}
else
touch gzip-ok
fi
exit ${STAT}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-13-2005 10:45 PM
тАО09-13-2005 10:45 PM
Re: exit in script!
rm -rf /directory
This will help if the file is read only.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-13-2005 10:53 PM
тАО09-13-2005 10:53 PM
Re: exit in script!
#!/bin/bash
# Exit Status
# 0 - Success; 1 - Tar failed;2 - gunzip failed
set -x
cd /cdr1/pmc
filename=/cdr1/backup.cdr.`date '+%d.%m.%Y.%k.%M.%S'`.tar
indexfile=/cdr1/backup.cdr.`date '+%d.%m.%Y.%k.%M.%S'`.txt
ls -l /cdr1/pmc >$indexfile
mkdir -p /cdr1/backup-tijd
for file in $(ls *.BF); do
mv -f ${file} /cdr1/backup-tijd
done
cd /cdr1/backup-tijd
tar cvf $filename .
if [ $? -ne 0 ];
then
echo "tar failed"
exit 1
else
rm -rf /cdr1/backup-tijd/
fi
gzip $filename
if [ $? -ne 0 ];
then
echo "gzip-failed"
exit 2
else
echo "gunzip-ok"
fi
exit 0
set +x
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-14-2005 01:30 AM
тАО09-14-2005 01:30 AM
Re: exit in script!
Why do you use set -x ?
Thanks