Scripted file move, automatically

On our business server which is used for storage of critical confidential information we have a shared folder which all finance managers must save thier credit reports to.  The problem is though that this must be emptied at least once an hour so that no other financse user may access anothers information.  What we would like to do is setup a file script that will not copy but move the files to another folder that is on the same drive, but is not shared.  This process would also have to be automated.  Thanks in advance for any ideas
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Unix or Linux?  If so a very simple crontab command would look like this:

# crontab -e

to edit the crontable; then type "i" and :

* 0-23 * * * mv /<source directory/* /<destination directory>

Press the Escape key and type ":wq!" and hit return

# crontab -l to show the contents of the crontab

on netware, you can give them write rights without read rights and use the cron and mv nlms

on windoze, you can use cron as well
I prefer the crontab way, but we're not sure your operating system.

Assuming you're using Windows of some sort, you can do it this way:

Create a batch file that will do the job for you.  An example is one that I've tested successfully below.  In notepad, an msdos window, or your favorite text file creator, make a file along the lines of this:

movestuff.bat (file exists within the dashed lines)

Save the batch file somewhere, and set up a Scheduled Task to run this for you hourly.

To explain a few things, the path names don't like having spaces in them when using the FOR command, and it doesn't help to put quotes around them either, because they are eaten up by the `for` command rather than passed along to the enumerated prompt.  For these you'll have to use the C:\DOCUME~1 notation.  The /R means do it for every subdirectory as well.  The quotes around the second %%F take into account spaces in the filenames.

This script "as is" is NOT secure at all!  If someone put a filename that already existed in your destination location, it will likely overwrite it or get stuck asking you for confirmation.  Shell scripting is very difficult in Windows when compared to GNU/Linux operations.  I would recommend reading through the "for /?" prompt in the cmd window to find out more, and possibly include some IF statements to check to see if any files already exist in your destination location (you can also type "if /?" for more info).     --- is a good place to start to make your script mode advanced and have more security and things like error checking.  In the meantime, what I have above will get you going, just be sure to have something else in place that protects your data from being overwritten.

Best of luck to you.
The 7 Worst Nightmares of a Sysadmin

Fear not! To defend your business’ IT systems we’re going to shine a light on the seven most sinister terrors that haunt sysadmins. That way you can be sure there’s nothing in your stack waiting to go bump in the night.

kleighAuthor Commented:
Sorry i forgot to specify this is on a windows 2k server machine
several cron's are available for windoze
see link above
kleighAuthor Commented:
I downloaded that Cron and it worked on my pc but when I put it on the server it wont work, and I am not sure why

I get this error message...
11.12.2003 10:58 move c:\REPORTS\ c:\STROPER\ /s
11.12.2003 10:58 Error: The specified file was not found.

and this is my crontab file

# move a file
* * * * * move c:\REPORTS\ *.* c:\STROPER\ /s

that * * * * * means run it every minute, I hope you know...

your best crontab line would start as follows:

0 * * * *

That means run the line at the zero minute, every hour, every day of the month, every month, every day of the week.

Also, no matter the OS you're better off having cron run a script anyway, so:

0 * * * * C:\scripts\movefile.bat > nul

the > nul means to not send you any error messages! (like, if there aren't any files to move)  and then, movefile.bat would contain your commands, such as what you have:
move c:\reports\*.* c:\stroper\

By the way, the move command on a Win2k server does not have a /s option like in your previous comment.  Also, you have a space between REPORTS\ and *.*, which is probably not good.

Maybe a better solution would be to xcopy the files and then delete them from the original location?  That way you could take care of subdirectories too.  For example:
xcopy /h /e /c /k C:\REPORTS\*.* C:\STROPER\
del /s /q /a C:\REPORTS\*.*

For each of these commands you can see exactly what command line attributes you want to use by doing a /? at the end of each of them.. you'd be amazed at whats there.

good luck again

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
btw, I reread your question and it said more than once an hour.  This would do the trick:

0,15,30,45 * * * * C:\scripts\movefile.bat > nul

That makes it run every 15 minutes.  modify accordingly.

BTW, the windows "at" command is sorta line cron.  with a slew of those you could make it run every day for each time you specify.  but, if cron works, it's superior anyway.
The user cron is running as may not have permissions on that directory
you can also use xxcopy to copy and remove the source files
kleighAuthor Commented:
ok ray i did exactly as you said.....

# move files
0 * * * * c:\scripts\movefile.bat > nul

that is my crontab

move c:\reports\*.*c:\stroper

that is movefile.bat

and the log is

11.12.2003 12:33 Cron started.
11.12.2003 12:35 c:\scripts\movefile.bat > nul
11.12.2003 12:35 c:\scripts\movefile.bat > nul
11.12.2003 12:36 c:\scripts\movefile.bat > nul
11.12.2003 12:36 c:\scripts\movefile.bat > nul
11.12.2003 12:37 c:\scripts\movefile.bat > nul
11.12.2003 12:37 c:\scripts\movefile.bat > nul
11.12.2003 12:38 c:\scripts\movefile.bat > nul
11.12.2003 12:38 c:\scripts\movefile.bat > nul
11.12.2003 12:39 c:\scripts\movefile.bat > nul
11.12.2003 12:39 Error: The specified file was not found.

and nothing happened........

got any more ideas?
move c:\reports\*.* c:\stroper\
needs a space -----^
and it needs /y if you want to overwrite the destination files
good call chicagoan.  also kleigh, try putting some files in c:\reports to see if they actually move

Also, I was telling you the 0 * * * * based on my linux manpage for cron, it might (but unlikely) be a different digit placement, i see that your log file was running it every minute?
kleighAuthor Commented:
I changed it to see if it woould work every minute, and if so then I would change it to a different schedule...

Ok well put those changes in and No errors this time, but ihave 253 txt files in the reports directory and none of them have moved...

Any more ideas?? Thanks again in advance
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.