So the final process I would like to achieve is:
find all files with this string smbprn_000_Microsoft_Word_-_OriginalFile.pdf
remove the smbprn_*_Microsoft_Word_-_part
append the file creation date onto the end of the filename: OriginalFile_DD_MM_YY.pdf
Move the file to a new location.
This can be in any order, I suspect moving the files to a new location first would be the best option not sure about the rest?
Was thinking of using this:
Wouldn't that be a rather arbitrary date, depending on when you run the command? Mayhap it's wiser to use creation or modification date for those files?
So the final process I would like to achieve is:
find all files with this string smbprn_000_Microsoft_Word_-_OriginalFile.pdf
remove the smbprn_*_Microsoft_Word_-_part
append the file creation date onto the end of the filename: OriginalFile_DD_MM_YY.pdf
Move the file to a new location.
This can be in any order, I suspect moving the files to a new location first would be the best option not sure about the rest?
Was thinking of using this:
I'm afraid I didn't really pay attention to what you were trying to do when I noticed that your script was missing the semicolon and just pointed out that adding the semicolon would get around the syntax error.
Looking at what you've come up with so far, I note that some of the things you're doing rely on features that are not portable (assuming that read with no operand will store the line read in the shell variable REPLY and depending on the ${var/.../...} variable expansions), or may be overly complex (using find if all of the files you want to process are in the current working directory). The following scripts don't depend on anything that is not required by the POSIX standards and the Single UNIX Specification, and they also add in the current date in the new names of the files in the format requested. (Both of these also include "echo" to verify that the commands that they execute will do what you want. If one of them does do what you want, remove the "echo " to actually rename the files.) As RudiC noted, the date supplied here will be the date when the file is renamed; not the date when the file was created.
First, if all of the files you want are in the current directory, try the following:
I use the Korn shell, but these scripts will work with any shell that behaves as specified by the standards.
Second, if some of the files you want to rename are in subdirectories try the following:
If you want all of the renamed files to be moved to the current directory instead of leaving them in the directory where they were found, change:
in the above script to:
or if you want to move all of the files to another (single) directory:
As long as you leave in the echo until confirm that one of these scripts does what you want, I don't think you need the cp. You could also turn the echo into a prompt showing that mv that is about to be executed and force the person running the script to reply "yes" to execute the mv command or "no" to skip the rename.
Wouldn't that be a rather arbitrary date, depending on when you run the command? Mayhap it's wiser to use creation or modification date for those files?
Yes you are probably correct, creation date would probably be the best.
@Don Cragun
Thanks for your advice, unfortunately most of it is completely over my head - hence why I post on here for help - I am not an IT professional
The idea is that a pdf will be produced by front-of-house staff from a word document that is populated from an MS Access application using a virtual cups-pdf printer on my ubuntu server. The pdf will then need to have the characters added by the pdf printer removed, the creation date added and moved to a new directory. From the new location the pdf will be edited by a user (me) on a tablet pc (probably an iPad) and then attached back to the MS Access record. I was planning to run the script that alters the pdf filename every 30secs or so as a cron job from a unprivileged user home directory. Hopefully this all makes sense?
Yes you are probably correct, creation date would probably be the best.
@Don Cragun
Thanks for your advice, unfortunately most of it is completely over my head - hence why I post on here for help - I am not an IT professional
The idea is that a pdf will be produced by front-of-house staff from a word document that is populated from an MS Access application using a virtual cups-pdf printer on my ubuntu server. The pdf will then need to have the characters added by the pdf printer removed, the creation date added and moved to a new directory. From the new location the pdf will be edited by a user (me) on a tablet pc (probably an iPad) and then attached back to the MS Access record. I was planning to run the script that alters the pdf filename every 30secs or so as a cron job from a unprivileged user home directory. Hopefully this all makes sense?
I am open to better suggestions if you have any
Thanks
OK. Back to basics:
1. Will all of the files you want to rename be in the same directory? If so, what is the name of that directory? If not, what are the names of all of the directories that will contain pdf files you want to rename?
2. What is the name of the directory where you want to place the renamed pdf files?
3. When you run the command:
what is the output?
If you want a script to run every 30 seconds, cron won't be sufficient; its finest granularity is 1 minute. And, if the system is busy, you could end up having two copies of your script running at the same time. If you run a script to rename files every few minutes after a file is converted, the likelihood that the current date and the file's creation date are different is pretty low (especially if the front end people who create the pdf files don't work between 11pm and 1am).
OK
But I want this script to work on later kernels and 64bit versions as well.
Quote:
1. Will all of the files you want to rename be in the same directory? If so, what is the name of that directory? If not, what are the names of all of the directories that will contain pdf files you want to rename?
Yes they will all be in the same directory, /media/PDF which is also mounted as an smb share on the LAN.
Quote:
2. What is the name of the directory where you want to place the renamed pdf files?
somewhere like /media/new_PDF but please make it apparent so I can alter it :-)
Quote:
If you want a script to run every 30 seconds, cron won't be sufficient; its finest granularity is 1 minute. And, if the system is busy, you could end up having two copies of your script running at the same time.
Thanks I didn't know this, is there a better method to achieve this?
Quote:
If you run a script to rename files every few minutes after a file is converted, the likelihood that the current date and the file's creation date are different is pretty low (especially if the front end people who create the pdf files don't work between 11pm and 1am).
Run the command:
The output should be something like:
Save the value marked in blue italics.
Create a file named something like get_pdf containing the following Korn shell script:
and replace the string marked in red in this script with the string you saved from the output of the type command.
Then run the commands:
You should then be able to run the command get_pdf no matter what directory you are in and it will display the commands it would use to rename and move PDF files from the directory /media/PDF to the directory /media/new_PDF.
If the commands displayed are the commands that you want this script to perform, change the line in $HOME/bin/get_pdf that currently says:
to:
Change the ../new_PDF in that line to any other directory if you want to change the directory to which the renamed files should be moved.
If you already have a script that you run after you have edited a PDF file to attach it "back to the MS Access record", I would suggest adding a call to get_pdf to the end of that script rather than trying to run it through cron. It won't consume as many resources in the background while you're doing other work and it will look for more PDF files to move as soon as you're ready to work on one. (Of course, if you do it this way and you get ahead of the "front-of-house staff", you'll have to run get_pdf manually until they catch up to you.)
Last edited by Don Cragun; 01-19-2013 at 11:22 PM..
Reason: quote out of place
This User Gave Thanks to Don Cragun For This Post:
Hi,
How to change the filenames with timestamp in sub folders
I have the following code to select the records.
find . -type f -name '*pqr*' -ctime 1 -print
The following is the example
app_root_dir="/`echo $ScriptDir | cut -d'/' -f2`"
$app_root_dir/../BadFiles directory
uvw.bad... (3 Replies)
Hi,
Can anyone let me know the command to know the list of filenames that have string 31 in their 4th and 5th positions inside the file:
grep -l "31" main*.txt
The above grep lists all the files which have 31 at any position but I want filenames having 31 at position 4 and position 5. (8 Replies)
I have a group of files in different directories with characters such as " ? : in the file names. How do I find these files and remove these characters on mass?
Thanks (19 Replies)
I have input file called file1 with characters that have \\ in it.
I cannot change input file, because it is generated earlier in script.
Now would like to replace string on line in file called bfile with output from file1
I have been using sed command.
$cat file1
pc//6sPxp==
$ cat scr1... (4 Replies)
I have the following code:
find /usr/local/test5 -type f -mtime +30 -exec ls -l {} \; | awk '{print $5, $6, $7, $8, $9}'
I have this as output:
14 Aug 12 00:00 /usr/local/test5/file1
14 Aug 12 00:00 /usr/local/test5/lastname,
The bolded part is where I run into trouble. The actual... (4 Replies)
Hi Gurus,
Do any kind souls encounter have the same script as mentioned here.
Find and compare filenames in different mount point and remove duplicates.
Thanks a million!!!
wanna13e (7 Replies)
Hi, guys, I'm not a high-end programmer, but I've been trying to write a script to remove all of the b.rtbn2.cn (and b.adserv.cn and any future variation) injected script tags on the server. (Still working on security fixes to prevent it in the future, just need to clean up now.)
My approach is... (1 Reply)
Hi,
I am having set of files whose names are stored in a file say "filelist.txt"
Now, I want to find all files contained in "filelist.txt" from my parent directory.
Is there any way to let find command understand "filelist.txt" just like we have option -f in awk.
I donot want to run a... (4 Replies)
Hi,
I need to write a small script to search in some specific directories to check if any file is present with a unix command name...
Means if the directory contains any files like cat, vi, grep, find etc i need to list those files into a file.
Please help
Thanks,
D (6 Replies)
How do I write the command to find all files with any lower case letters in the filename? I have tried
find . -name *\(a-z\) and a lot of combinations like that, without success.
thanks
JP:confused: (4 Replies)