Help with gunzip in shell script.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with gunzip in shell script.
# 1  
Old 02-15-2012
Help with gunzip in shell script.

Hi All,

I'm tweaking a script found online. script gunzips the files in current dir.
My modifications are to check:

1. if the backup already exists, if yes quit else else go on -- this works.
2.once gunzipped file is created, cp it to archive dir and then delete the file in existing dir -- this does not work

here is the error i get:
cp: omitting directory `/home/blah/'
rm: cannot remove `/home/blah/': Is a directory
looks like $GZ is not actually being populated. Can anyone figure out why?

Code:
#!/bin/bash
#  Backs up all files in current directory modified within last 24 hours

BACKUPFILE=backup-$(date +%m-%d-%Y)

if [ -s $BACKUPFILE.tar.gz ]
then
echo "backup already created"
exit 0
fi

#if backup not already created, tar the files.
#all o/p is stored in archive.log file.
archivedir=`pwd`/archive
find . -mtime -1 -type f -print0 | xargs -0 tar rvf "$BACKUPFILE.tar" &>$archivedir/archive.log

GZ=$(gzip $BACKUPFILE.tar)

# move the zipped file to archive directory. Delete the zipped file in current dir.
cp -ip `pwd`/$GZ $archivedir
rm `pwd`/$GZ

exit 0

# 2  
Old 02-15-2012
Unless your version of gzip is very different than mine, with no options gzip shouldn't be writing to stdout and your variable should be empty. You can assume that gzip will add .gz to the original file name, so you could just code

Code:
GZ="$BACKUPFILE.tar.gz"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

command for gunzip?

Hi All This is very basic query but I have a huge folder named backup that I need to transfer. What is the command to convert the file in format backup.tar.gz so that I could transfer the folder. Is the command gzip filename? Thanks Sonia. :wall: (6 Replies)
Discussion started by: sonia102
6 Replies

2. Shell Programming and Scripting

gunzip status

Hi, I'm trying to run my application on HP-UX server. I have to extract a *.tar.gz file. I'm doing that now in 2 steps. first I gunzip it and then pax it. My question is how can I check whether the data in the *.tar.gz file is corrupted or not?? Now, I'm trying to do this... (1 Reply)
Discussion started by: Kyaw Lwin Phyo
1 Replies

3. Shell Programming and Scripting

Gunzip files

Hi ALL, Am working with the gunzip command to zip all the old files having 10 days am using the command find . -name '*.log' -type f -mtime +10 -exec gunzip {} \; am facing two issues 1.)it displays the files which are all older than a year 2.)when am trying to gunzip all the... (2 Replies)
Discussion started by: thelakbe
2 Replies

4. SCO

gunzip problem

hi On one of our SCO 5.0.6 server gunzip doesn't work and I'm getting this error message: # gunzip dynamic linker: gunzip: symbol not found: ___requires_updated_system_library_se_ Killed What's missing? (0 Replies)
Discussion started by: ccc
0 Replies

5. Shell Programming and Scripting

Help with gunzip

Hi All, I have a file "HOTEL_INFO.zip" and getting the below errors: server1:/home/arun# gunzip -S .zip HOTEL_INFO.zip gunzip: HOTEL_INFO.zip: first entry not deflated or stored -- use unzip server1:/home/arun#unzip HOTEL_INFO.zip ksh: unzip: not found. ... (11 Replies)
Discussion started by: Arunprasad
11 Replies

6. UNIX for Dummies Questions & Answers

gunzip

I have a zip file as a.zip and it contains 1m xml files. like a1.xml, a2.xml.... The size is also very big nearly 1GB. I want to extract only a123.xml. Can any one help how can I do this? (1 Reply)
Discussion started by: siba.s.nayak
1 Replies

7. Shell Programming and Scripting

Help on gunzip

Hi All, I am using UNIX command to unzip the files gzip -d9 DW_*.gz The Xmls are compressed using gzip and it is received in the .gz format at UNIX box which need to be uncompressed. The above command is working fine for 400 compressed xmls(.gz files) but when the count becomes 401 or more i... (7 Replies)
Discussion started by: Codesearcher
7 Replies

8. UNIX for Dummies Questions & Answers

gunzip question

unzip test.zip ==> This uncompresses and keeps the original zip file. gunzip test.gz ==> Removes the .gz file after uncompressing. Is there any switch to make the .gz file available after uncompression. Thanx in advance. (3 Replies)
Discussion started by: devs
3 Replies

9. UNIX for Dummies Questions & Answers

gunzip error

While trying to gunzip afile I get the following error message ls -l UK_US_02310.dat.gz -rwxrwxrwx 1 imis abint 348854527 Jan 8 00:17 UK_US_02310.dat.gz gunzip UK_US_02310.dat.gz gunzip: UK_US_02310.dat.gz: invalid compressed data--format violated I can gzcat the file and pipe to... (3 Replies)
Discussion started by: mccoubreyr
3 Replies

10. UNIX for Dummies Questions & Answers

Gunzip

Hi can't unzip a gz file in TurboLinux 7.0 when i'm trying this gunzip filename.tar.gz it always says not in gzip format what should I do...please help me (4 Replies)
Discussion started by: CreamHarry
4 Replies
Login or Register to Ask a Question