[Solved] Help with a script to gzip/move files


 
Thread Tools Search this Thread
Operating Systems HP-UX [Solved] Help with a script to gzip/move files
# 1  
Old 11-23-2011
[Solved] Help with a script to gzip/move files

Hi

Please can you help me in writing a script to find files on a specific directory, and of extension "tap" but only of the month of september, gzip and move them to another directory.
Your help will be appreciated.
# 2  
Old 11-24-2011
Yes...
What have you done so far?
Why don't you move the files first then gzip all of them using * ?
# 3  
Old 11-24-2011
I think the issue is identifying just the files from September:
Code:
#! /bin/ksh

BEGIN=$(mktemp)
END=$(mktemp)

trap "rm -f ${BEGIN} ${END}" EXIT

touch --date='09/01' $BEGIN
touch --date='10/01' $END

find "${SOURCEDIR}" -maxdepth 1 -type f -name '*.tap' -newer $BEGIN ! -newer $END -print \
| while read file; do
    echo "${file}"
    gzip -9 "${file}"
    mv "${file}.gz" "${DESTDIR}"
done

rm $BEGIN $END

# 4  
Old 11-24-2011
Hi

VBE:

I can move the files them gzip them, but I found something else that puzle me, look:


Code:
itc01[132]/data/ICTPRD/bmd1/rating/processed #find . -type f \( -name "*.tap" \) -exec ls -lrt {} \; | head
-rw-r--r--   1 ictprd     ict          50184 Nov  2 15:20 ./ICTCDMOZ01AGOUT0280620111102151703.tap
-rw-r--r--   1 ictprd     ict          98072 Nov  2 15:20 ./ICTCDMOZ01AGOUT0280820111102151708.tap
-rw-r--r--   1 ictprd     ict         158752 Nov  2 15:20 ./ICTCDMOZ01AGOUT0281020111102151713.tap
-rw-r--r--   1 ictprd     ict         108896 Nov  2 15:20 ./ICTCDMOZ01AGOUT0280920111102151711.tap
-rw-r--r--   1 ictprd     ict          38704 Nov  2 15:20 ./ICTCDMOZ01AGOUT0281120111102151716.tap
-rw-r--r--   1 ictprd     ict          39360 Nov  2 15:20 ./ICTCDMOZ01AGOUT0281220111102151719.tap
-rw-r--r--   1 ictprd     ict          76424 Nov  2 15:20 ./ICTCDMOZ01AGOUT0280720111102151706.tap
-rw-r--r--   1 ictprd     ict          26240 Nov  2 15:20 ./ICTCDMOZ01AGOUT0281320111102151721.tap
-rw-r--r--   1 ictprd     ict          68224 Nov  2 15:20 ./ICTCDMOZ01AGOUT0281420111102151722.tap
-rw-r--r--   1 ictprd     ict          10824 Nov  2 15:20 ./ICTCDMOZ01AGOUT0281620111102151725.tap
itc01[133]/data/ICTPRD/bmd1/rating/processed #
itc01[133]/data/ICTPRD/bmd1/rating/processed #ls -lrt *.tap | head
-rw-r--r--   1 ictprd     ict          12464 Sep 21 12:33 ICTCDMOZ01AGOUT0274620110921123027.tap
-rw-r--r--   1 ictprd     ict          27552 Sep 21 12:33 ICTCDMOZ01AGOUT0274720110921123037.tap
-rw-r--r--   1 ictprd     ict          20008 Sep 21 12:33 ICTCDMOZ01AGOUT0274820110921123052.tap
-rw-r--r--   1 ictprd     ict          15088 Sep 21 12:33 ICTCDMOZ01AGOUT0274920110921123100.tap
-rw-r--r--   1 ictprd     ict           8856 Sep 21 12:33 ICTCDMOZ01AGOUT0275020110921123103.tap
-rw-r--r--   1 ictprd     ict           7544 Sep 21 12:33 ICTCDMOZ01AGOUT0275120110921123106.tap
-rw-r--r--   1 ictprd     ict          23616 Sep 21 12:33 ICTCDMOZ01AGOUT0275320110921123110.tap
-rw-r--r--   1 ictprd     ict          20664 Sep 21 12:35 ICTCDMOZ01AUSOP0281420110921123227.tap
-rw-r--r--   1 ictprd     ict          33784 Sep 21 12:35 ICTCDMOZ01AUSOP0281520110921123233.tap
-rw-r--r--   1 ictprd     ict          39360 Sep 21 12:35 ICTCDMOZ01AUSOP0281620110921123238.tap
itc01[134]/data/ICTPRD/bmd1/rating/processed #


Why is if I use find, I see only november files, but if I do ls -lrt *.tap I see september files???

LUDWIG:

You are right the issue is september only:
I am going to test your script , although I did not understand the "gzip -9" section. can you explain? if its possible


regards

Last edited by pludi; 11-24-2011 at 10:35 AM..
# 5  
Old 11-24-2011
Quote:
Originally Posted by fretagi
Hi

VBE:

I can move the files them gzip them, but I found something else that puzle me, look:


Code:
itc01[132]/data/ICTPRD/bmd1/rating/processed #find . -type f \( -name "*.tap" \) -exec ls -lrt {} \; | head
-rw-r--r--   1 ictprd     ict          50184 Nov  2 15:20 ./ICTCDMOZ01AGOUT0280620111102151703.tap
-rw-r--r--   1 ictprd     ict          98072 Nov  2 15:20 ./ICTCDMOZ01AGOUT0280820111102151708.tap
-rw-r--r--   1 ictprd     ict         158752 Nov  2 15:20 ./ICTCDMOZ01AGOUT0281020111102151713.tap
-rw-r--r--   1 ictprd     ict         108896 Nov  2 15:20 ./ICTCDMOZ01AGOUT0280920111102151711.tap
-rw-r--r--   1 ictprd     ict          38704 Nov  2 15:20 ./ICTCDMOZ01AGOUT0281120111102151716.tap
-rw-r--r--   1 ictprd     ict          39360 Nov  2 15:20 ./ICTCDMOZ01AGOUT0281220111102151719.tap
-rw-r--r--   1 ictprd     ict          76424 Nov  2 15:20 ./ICTCDMOZ01AGOUT0280720111102151706.tap
-rw-r--r--   1 ictprd     ict          26240 Nov  2 15:20 ./ICTCDMOZ01AGOUT0281320111102151721.tap
-rw-r--r--   1 ictprd     ict          68224 Nov  2 15:20 ./ICTCDMOZ01AGOUT0281420111102151722.tap
-rw-r--r--   1 ictprd     ict          10824 Nov  2 15:20 ./ICTCDMOZ01AGOUT0281620111102151725.tap
itc01[133]/data/ICTPRD/bmd1/rating/processed #
itc01[133]/data/ICTPRD/bmd1/rating/processed #ls -lrt *.tap | head
-rw-r--r--   1 ictprd     ict          12464 Sep 21 12:33 ICTCDMOZ01AGOUT0274620110921123027.tap
-rw-r--r--   1 ictprd     ict          27552 Sep 21 12:33 ICTCDMOZ01AGOUT0274720110921123037.tap
-rw-r--r--   1 ictprd     ict          20008 Sep 21 12:33 ICTCDMOZ01AGOUT0274820110921123052.tap
-rw-r--r--   1 ictprd     ict          15088 Sep 21 12:33 ICTCDMOZ01AGOUT0274920110921123100.tap
-rw-r--r--   1 ictprd     ict           8856 Sep 21 12:33 ICTCDMOZ01AGOUT0275020110921123103.tap
-rw-r--r--   1 ictprd     ict           7544 Sep 21 12:33 ICTCDMOZ01AGOUT0275120110921123106.tap
-rw-r--r--   1 ictprd     ict          23616 Sep 21 12:33 ICTCDMOZ01AGOUT0275320110921123110.tap
-rw-r--r--   1 ictprd     ict          20664 Sep 21 12:35 ICTCDMOZ01AUSOP0281420110921123227.tap
-rw-r--r--   1 ictprd     ict          33784 Sep 21 12:35 ICTCDMOZ01AUSOP0281520110921123233.tap
-rw-r--r--   1 ictprd     ict          39360 Sep 21 12:35 ICTCDMOZ01AUSOP0281620110921123238.tap
itc01[134]/data/ICTPRD/bmd1/rating/processed #


Why is if I use find, I see only november files, but if I do ls -lrt *.tap I see september files???
Because if you run any command through -exec the files names are passed along one by one. So you're not doing ls -lrt *.tap, but
Code:
ls -lrt ./ICTCDMOZ01AGOUT0280620111102151703.tap
ls -lrt ./ICTCDMOZ01AGOUT0280820111102151708.tap
ls -lrt ./ICTCDMOZ01AGOUT0281020111102151713.tap
ls -lrt ./ICTCDMOZ01AGOUT0280920111102151711.tap
ls -lrt ./ICTCDMOZ01AGOUT0281120111102151716.tap
[...]

This User Gave Thanks to pludi For This Post:
# 6  
Old 11-24-2011
Quote:
Originally Posted by fretagi
Why is if I use find, I see only november files, but if I do ls -lrt *.tap I see september files???
You're using head, so you're only showing part of the output. Both commands will be returning all the files, but not necessarily in the same order (the ordering options on -exec ls won't apply to find, since it's processing files 1 at a time).
This User Gave Thanks to CarloM For This Post:
# 7  
Old 11-24-2011
If you want those Sep files why dont you use
Code:
 ll *.tap |grep " Sep "

If you are happy with what you see, then :
Code:
 mv $(ll *.tap | grep " Sep " |awk '{print $9}') newDest/.

This User Gave Thanks to vbe For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to move certain no. of files every second

Hi All, I am new to Linux/Scripting and need some assistance in coming up with a script that can move certain amount of files from one directory to other every seconds. Usercase: We have around 100k files in tmp directory on my server which needs to be moved to another folder to get... (3 Replies)
Discussion started by: Raj1184
3 Replies

2. Shell Programming and Scripting

Script move files by name

hi, I have a lot of files named xxxxx__AA.txt, xxxxx__BB.txt, xxxxx__CC.txt and I would like to move xxxxx__AA.txt in AA directory, xxxxx__BB.txt in BB etc. Could you help me do it in bash script? (5 Replies)
Discussion started by: corfuitl
5 Replies

3. Shell Programming and Scripting

help with a script to gzip/move files

Hi Please can you help me in writing a script to find files on a specific directory, and of extension "tap" but only of the month of september, gzip and move them to another directory. Your help will be appreciated. (4 Replies)
Discussion started by: fretagi
4 Replies

4. Shell Programming and Scripting

Need shell script to move files

Hi , I need a simple shell script to move the files from one directory to another directory after every 1 hour..!!! ?? (1 Reply)
Discussion started by: SARAL SAXENA
1 Replies

5. Shell Programming and Scripting

Need script to move files based on name

Hi folks, I'm new here and appreciate greatly any help. I have a bunch of files that need be moved and renamed. Fortunately, they are all in sequence... Present filename and path: /.catalog1/t76038_842-01 Move to: /.catalog1/76038-01 So, we need to drop the... (8 Replies)
Discussion started by: axslinger
8 Replies

6. UNIX for Dummies Questions & Answers

Script to move blank files

Anyone could give me an example of scrip to move blank files found into a dir? Thanks, Leandro Takeda (3 Replies)
Discussion started by: letakeda
3 Replies

7. Shell Programming and Scripting

Script to move trace files

Please debug this shell script for me.. Basically the idea is to run the script, based on the command to move some trace files to a separate directory and I am getting the error. Only the COMMAND that has rm {} works and I basically want to use it for the fourth one. Please try for the 2nd, 3rd and... (4 Replies)
Discussion started by: ST2000
4 Replies
Login or Register to Ask a Question