Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 683
  • Last Modified:

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
0
kleigh
Asked:
kleigh
  • 5
  • 4
  • 4
  • +1
2 Solutions
 
durindilCommented:
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

0
 
chicagoanCommented:
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/
0
 
raybassCommented:
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.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
kleighAuthor Commented:
Sorry i forgot to specify this is on a windows 2k server machine
0
 
chicagoanCommented:
several cron's are available for windoze
see link above
0
 
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
                 

0
 
raybassCommented:
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
0
 
raybassCommented:
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
 
chicagoanCommented:
The user cron is running as may not have permissions on that directory
0
 
chicagoanCommented:
you can also use xxcopy to copy and remove the source files
0
 
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?
0
 
chicagoanCommented:
move c:\reports\*.* c:\stroper\
needs a space -----^
and it needs /y if you want to overwrite the destination files
0
 
raybassCommented:
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?
0
 
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
0

Featured Post

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

  • 5
  • 4
  • 4
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now