I' writing a script trying to archive the oldest two directories from one place, tar them, and move them to another.
The problem I'm running into is that the oldest two directories, and some others, were created the same month, date, and different only because their modification time was one or two minutes apart. The oldest two have dates of 2012-07-25, when I run the directory exists check, it will created the directory 2012-07 and move ONE of the two targeted directories into it, the other tar does not go in the target directory but one level up. I want it in /temp/dir/2012-07 one of them goes into that and the other goes to /temp/dir.
I cannot figure out what is in those arrays. Parsing ls into an array, and find into a string variable, is very likely to eventually break. It is best to operate using NUL delimited filenames printed from find. We can also have it print the date.
remove the echos if it prints what seems correct
This User Gave Thanks to neutronscott For This Post:
if [[ -d ${ARCHIVE}${CUT[$i]} ]]
then
tar -zcvf ${names[$i]}.tar.gz ${names[$i]}
mv ${names[$i]}.tar.gz ${ARCHIVE}${CUT[$i]}
else
mkdir ${ARCHIVE}${CUT[$i]}
fi
[/CODE]
If the archive destination doesn't exist, the else-block creates it but doesn't tar anything. The loop moves on to the second directory, and retests for the archive destination's existence. This time it's there and that second directory is archived.
Disentangle the directory creation from the tarring. In pseudocode, instead of ...
... try ...
Regards,
Alister
Thanks neutronscott it worked, can you explain in a little more detail what your code does though? I am unfamiliar with printf, this section was hardest to read.
Quote:
-printf '%Ts %TY-%Tm %f\0' | sort -znk1 | while read -rd '' epoch date dir && ((max++ < 2))
I understand it for the most part, I'm guessing the...
are the year and month, and that the...
is sorting in modified date order? Is the...
taking the input from the printf?
This helped a lot but I still do not understand why one tar was going into the created directory and the other was not with my script. I tried Alister's script and understand his change, but it yielded me the same result. Both tar files were still not going into the destination directory, only one was even though they should both have been in the same directory.
Thanks neutronscott it worked, can you explain in a little more detail what your code does though? I am unfamiliar with printf, this section was hardest to read.
It's in the find manual. Rather than just printing file names, we include the modify time in epoch and also YYYY-MM format, then finally the filename NUL terminated. So even a filename with a new-line won't mess it up.
Quote:
Originally Posted by jrymer
the...
is sorting in modified date order? Is the...
taking the input from the printf?
-z is to print it back NUL terminated (GNU extention). -nk1 is for numerical sort on first position... bash's read you can set the delimiter to be different than newline. here we set it to '' (empty string, NUL). Yes, it reads off what is piped in from find's -printf for further processing in the shell's while loop.
Quote:
Originally Posted by jrymer
This helped a lot but I still do not understand why one tar was going into the created directory and the other was not with my script. I tried Alister's script and understand his change, but it yielded me the same result. Both tar files were still not going into the destination directory, only one was even though they should both have been in the same directory.
If alister's suggestion did not fix your script, i'd try bash -x ./script to see exactly what it is doing to follow the logic. It was my first thought.
Can anyone offer any advice on how to modify the script below to work on a new system we have, that has no graphics capability? We admin the system through a serial RAS device. I've tried running the below script through the RAS and through an ssh -X session. It failed with something like "GTK... (3 Replies)
Requirement:
Under fuse application we have placeholders called containers;
Every container has their logs under:
<container1>/data/log/fuse.log
<container1>/data/log/fuse.log.1
<container1>/data/log/fuse.log.XX
<container2>/data/log/fuse.log... (6 Replies)
HI,
I need to move all files from a dir & its all subdir to Archive folder which is indise dir only. and moved filename should changed to complete path ( Like Dir_subdir_subdir2_.._filename ). also all files names shoud capture in a file in order to mail
I written below code ... (11 Replies)
I have a set of files in path /ifx01/etldata/lmt/
a.xml
b.xml
I have to archive & move these files to path /ifx01/etldata/archive ,so that not even the original files should exists.
After acrhiving there should be no files in path /ifx01/etldata/lmt/ (6 Replies)
AIX 5.3-5300.09.06.1013 (AIX 5.3 TL9 SP6)
# startsrc -s xntpd -a "-x"
(with -x at the end of the xntpd line in /etc/rc.tcpip, too.)
will run for 5-15 minutes, and then die.
# errpt -a
with a search on xntpd gives me this:
------------------------------------------------
LABEL: ... (7 Replies)
Hi there,
I have one huge archive (it's a system image).
I need sometime to create smaller archives with only one or two file from my big archive.
So I'm looking for a command that extracts files from an archive and pipe them to another one.
I tried the following :
tar -xzOf oldarchive.tgz... (5 Replies)
hi all.
Please help me with archiving previous day syslog files.
the files have no extension and have the format YYYY-MM-DD.
I want to archive the file then move it to some other machine.
thanks. (2 Replies)
Hello:
NOOB here. I attempted to use smit mkcd. Failed on first attempt, not enough space. 2nd attempt tried to place iso on /usr, not enough space there. Cleanup ran for about 5 minutes after aborting. Now AIX won't boot. LCD display on 7029-6E3 says: 0517 MOUNT /USR. Attempted to boot from CD... (11 Replies)
After I log ino the machine, a window pops up indicating that I should check that the HOSTNAME is the same in these three files
/etc//rc.configd/netconf
/etc/hosts
/var/adm/inetd.sec
How do I change the hostname in these files?
Thanks,
Mike h (1 Reply)
hey programmers!
1-why won't gcc accept as an argument? i tried the recommendations on the man page of getch(),..etc. nothing worked.
2-why it won't see <iostream> && <fstream> even if i implemented the function as follow
std::cout<<"..etc"<<endl;
3-after i type this code in it gives... (6 Replies)