need to rename a file automatically

Microsoft Windows 7 home premium
March 18, 2015 at 07:18:01
Specs: Windows 7, Intel i7 / 4 GB
Ok, so I'm running an enterprise server app that everyday there are these "noloads" files that didn't load. I have a script that I created that runs in crontab that automatically renames the files from noload to log which causes the daemon to automatically to try reprocess the files. But when I do it, I rename the file from file.noload to file.1.log. I put the .1. in there. Then when the files are processed, they are automatically transfered to a DONE folder. But I check the DONE folder and then I manually rename the file.1.log file to file.2.log. .2. just indicates to me I've already checked it.

I tried creating a script like this but it isn't working...

#!/bin/sh -x
#Version 5.0
###############
# P2_rename.sh
# This script rename noload files to log to be reprocessed.
###############

cd /P2/collector/queue/hub1_mill_prd/
rename .1.log .2.log *.1.log
rename .1.meta .2.meta *.1.meta

cd /P2/collector/queue/hub3_mill_prd/
rename .1.log .2.log *.1.log
rename .1.meta .2.meta *.1.meta

exit 0


Here's the output...

ls -1
000-2015-03-17T11:01:04-0-r_hub3_mill_prd.1.log
000-2015-03-17T11:01:04-0-r_hub3_mill_prd.1.meta
000-2015-03-17T12:01:17-0-r_hub3_mill_prd.1.log
000-2015-03-17T12:01:17-0-r_hub3_mill_prd.1.meta
000-2015-03-17T13:01:04-0-r_hub3_mill_prd.1.log
000-2015-03-17T13:01:04-0-r_hub3_mill_prd.1.meta
000-2015-03-17T14:01:03-0-r_hub3_mill_prd.1.log
000-2015-03-17T14:01:03-0-r_hub3_mill_prd.1.meta
000-2015-03-17T15:01:03-0-r_hub3_mill_prd.1.log


when running the script, I get the errors...

al001p2sapp02:/P2/collector/queue/hub3_mill_prd/done # ./rename.sh
+ cd /P2/collector/queue/hub1_mill_prd/
+ rename .1.log .2.log '*.1.log'
rename: renaming *.1.log to *.2.log failed: No such file or directory
+ rename .1.meta .2.meta '*.1.meta'
rename: renaming *.1.meta to *.2.meta failed: No such file or directory
+ cd /P2/collector/queue/hub3_mill_prd/
+ rename .1.log .2.log '*.1.log'
rename: renaming *.1.log to *.2.log failed: No such file or directory
+ rename .1.meta .2.meta '*.1.meta'
rename: renaming *.1.meta to *.2.meta failed: No such file or directory
+ exit 0
al001p2sapp02:/P2/collector/queue/hub3_mill_prd/done #

(I went through the script and erased my client mnemonic so I'm not sure if I ruined the logic of the script a little.)

I used this script to rename them from .noload to .1.log and that script is in crontab and has been working for about a month now with no problems, so the logic of the script should be working. I took that script and copied it and created a new script. I just took that same script and changed the spots where it had .log to .1.log and where it had .1.log to .2.log. I just use the 2 to know that I've already looked at these.

message edited by dorlow


See More: need to rename a file automatically

Report •

#1
March 19, 2015 at 08:59:09
In your script, what is the command rename? That is not a common Unix command I am aware of. Anyway, your rename command does not seem to be working the way the class Unix move command, mv, works.

That is where I would start looking.


Report •
Related Solutions


Ask Question