kleigh
asked on
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
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
http://cygwin.dp.ua/pub/mirrors/cygwin/release/cron/
on windoze, you can use cron as well
http://cygwin.dp.ua/pub/mirrors/cygwin/release/cron/
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 edit.com window, or your favorite text file creator, make a file along the lines of this:
movestuff.bat (file exists within the dashed lines)
---------------------
@ECHO OFF
FOR /R C:\SECUREFILES\ %%F IN (*.*) DO MOVE "%%F" C:\PRIVATELOCATION\
---------------------
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).
http://www.windowsshellscripting.com/ --- 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.
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 edit.com window, or your favorite text file creator, make a file along the lines of this:
movestuff.bat (file exists within the dashed lines)
---------------------
@ECHO OFF
FOR /R C:\SECUREFILES\ %%F IN (*.*) DO MOVE "%%F" C:\PRIVATELOCATION\
---------------------
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).
http://www.windowsshellscripting.com/ --- 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.
ASKER
Sorry i forgot to specify this is on a windows 2k server machine
several cron's are available for windoze
see link above
see link above
ASKER
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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
ASKER
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 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?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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?
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?
ASKER
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
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
# 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