Actually, what they all have that can distinguish them is 20120423 which is a date - 23rd April 2012 and the trailing 6 numbers (161300) of each file is time 16H13:00 so, I'll have different files with different time but of same date.
I changed directories as specified and ran the code the way it was sent and nothing changed.
i.e no files were moved nor zipped
But I came across one that works but this is more of a manual process:
Step 1: This moved all files with _20120630 into target directory
$ find . -name "*_20120630*" -print -exec mv {} /home/oracle/work/target \;
Step 2: Tar the target directory
$ tar -cvf 30jun2012.tar /home/oracle/work/adams_de/target
Step 3: Compress the tar file
$ gzip 30jun2012.tar
This I just tested and it worked perfectly but I want a scenario where I can automate this task and also delete the files that have already been compressed. I want to run this via cron.
I'm simulating with this created directories. I have 3 files in /home/oracle/work/adams_de/source and /home/oracle/work/adams_de/target - the target directory.
Below is the error I get:
but all those directories exist.
I just tested both directories earlier and I have access to them.
Thanks a lot.
---------- Post updated at 04:28 PM ---------- Previous update was at 04:23 PM ----------
And for your info I'm running on AIX 6.
option -z for tar doesn't work on AIX 6. And one more thing, I tried with both
and
the trailing forward slash but same error.
---------- Post updated at 04:33 PM ---------- Previous update was at 04:28 PM ----------
RudiC,
Sorry my mistake, now they were moved to the target directory but not tar and compressed.
for i in /home/oracle/work/adams_de/source/*20120630??????; do mv $i /home/oracle/work/adams_de/target ; done;
seems to work.
Next step: tar'ring. Your tar command
tar -cvf 30jun2012.tar /home/oracle/work/adams_de/target/ gzip 30jun2012.tar
looks a bit strange to me, ar least the gzip should be separated with a ; . AFAIK tar writes to standard output if no archive file given and thus you can pipe that to gzip. Try the following:
tar -cv /home/oracle/work/adams_de/target/|gzip > /dest/dir/30jun2012.tgz
That's what I remembered as well; but my linux version does it without - , in fact - gives an error. So Creems needs to test which one will work for him on his AIX. Another option would be to use tar's -O option, this would definitely tar to stdout.
*shrug* My linux version doesn't, my Linux version needs it, and it's just ordinary GNU tar. Maybe you're using something odd like busybox tar, or some sort of wrapper script. Most tars will complain if you don't give it some sort of output option like -f.
On systems which don't support -, you may have to do something kludgy like /proc/self/fd/1.