For starters, I'm not the most advanced scripter. I was asked to create a script that would search through a directory for print files older than 14 days and move them to an archive directory. There are several directories that will have corresponding archive directories with them. To test this, I created two text files that would have the source directory and the destination directory. Things went fine when there was only one directory path in each file. However, when I added another directory path to each file, the script moved the first archive folder into the second archive folder.
The files found in the first line of printdirs.txt
should be moved to the path found in the first line of archivedirs.txt
. Then the loop runs again and the files found in the path on the second line of printdirs.txt
should be moved to the path found on the second line of archivedirs.txt
and so forth.
Here is what the script looks like:
#!/usr/bin/ksh printlist=/u/lawson/stage/Scripts/printdirs.txt archivelist=/u/lawson/stage/Scripts/archivedirs.txt # Checking the archive list and moving files for i in $(cat $printlist) ; do cd $i /usr/bin/find . -mtime +14 -type f -exec mv "{}" $(cat $archivelist) \; done
Here is what the text files contain:
$ cat printdirs.txt /u/lawson/law/print/lawson/tim/1 /u/lawson/law/print/dgfinance/monday190/1 $ cat archivedirs.txt /u/lawson/law/print/archive /u/lawson/law/print/archive2
How can I get the script to loop for each corresponding line and not copy the "archive" folder into the "archive2" folder?
UPDATE: Updated the script with terdon's help. Here is the output after adding the echo command:
# ./printarchive2.ksh /usr/bin/find /u/lawson/law/prin -mtime +14 -type f -exec mv /lawson/tim/1 /u/lawson/law/print/archive {} + /usr/bin/find /u/lawson/law/prin -mtime +14 -type f -exec mv /dgfinance/monday190/1 /u/lawson/law/print/archive2 {} +
The script terdon wanted me to use is removing the "t" from the directory paths. I tested it out by changing the "t" to an "n". It removed the letter "n" from my directory paths. Is there another way to signify a tab field separator that Korn shell can read because apparently this does not work in KSH.