Solved

Scripted file move, automatically

Posted on 2003-12-09
14
669 Views
Last Modified: 2010-04-03
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
Comment
Question by:kleigh
  • 5
  • 4
  • 4
  • +1
14 Comments
 
LVL 6

Expert Comment

by:durindil
ID: 9908101
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
 
LVL 18

Expert Comment

by:chicagoan
ID: 9908213
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
 
LVL 3

Expert Comment

by:raybass
ID: 9910455
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
 

Author Comment

by:kleigh
ID: 9919877
Sorry i forgot to specify this is on a windows 2k server machine
0
 
LVL 18

Expert Comment

by:chicagoan
ID: 9919992
several cron's are available for windoze
see link above
0
 

Author Comment

by:kleigh
ID: 9920966
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
 
LVL 3

Accepted Solution

by:
raybass earned 450 total points
ID: 9921514
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 3

Expert Comment

by:raybass
ID: 9921540
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
 
LVL 18

Expert Comment

by:chicagoan
ID: 9921563
The user cron is running as may not have permissions on that directory
0
 
LVL 18

Expert Comment

by:chicagoan
ID: 9921576
you can also use xxcopy to copy and remove the source files
0
 

Author Comment

by:kleigh
ID: 9921699
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
 
LVL 18

Assisted Solution

by:chicagoan
chicagoan earned 50 total points
ID: 9921800
move c:\reports\*.* c:\stroper\
needs a space -----^
and it needs /y if you want to overwrite the destination files
0
 
LVL 3

Expert Comment

by:raybass
ID: 9921933
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
 

Author Comment

by:kleigh
ID: 9922038
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Sometimes the best way to deal with an infected computer is to boot from external media and run your tools from there.  The reason you may wish to do this really depends on the infection.  Some malware is so recalcitrant that no matter what you do i…
AWS Glacier is Amazons cheapest storage option and is their answer to a ‘Cold’ storage service.  Customers primarily use this service for archival purposes and storage of infrastructure backups.  Its unlimited storage potential and low storage cost …
This video teaches viewers how to encrypt an external drive that requires a password to read and edit the drive. All tasks are done in Disk Utility. Plug in the external drive you wish to encrypt: Make sure all previous data on the drive has been …
This Micro Tutorial will teach you how to reformat your flash drive. Sometimes your flash drive may have issues carrying files so this will completely restore it to manufacturing settings. Make sure to backup all files before reformatting. This w…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now