Name: Nivin37 Date: April 30, 2008 at 01:29:59 Pacific Subject: bat: Copy remote file & rename OS: XP CPU/Ram: 2GHz/1GB
Comment:
Hi, I need a batch file to do the following, however I do not have the knowledge, can anyone help?
1. Batch file to run every hour.
2. Copy file from remote PC on same subnet to local dir or dir on another remote PC.
3. Rename the file with the current date & time, keeping the extn (htm)
Though you might like the reason...
I Have a NASLite-2 server that keeps crashing every couple of days, it has a syslog that is not saved & a new one is generated each time the server is rebooted & you are unable to retrieve the syslog after the NASLite-2 server goes south. So in using the batch file I hope to find the u/s hardware & replace it.
The following batch file copies the current file to a local folder and renames it to the current date and time: __________________________________________________ @echo off setlocal set LocalFolder=C:\Logs set RemoteFile=\\remotehost\C$\Logs\syslog.htm set timestamp=%DATE:/=-%-%TIME:~0,2%%TIME:~3,2% copy %RemoteFile% %LocalFolder%\%timestamp%.* __________________________________________________
Note that you have to edit the above to use the correct folder and file names. Note that the time stamp has some characters removed (such as the colon) which are not allowed in file names.
To run this file every hour, create a scheduled task in Control Panel. Get it to run every day, then click Advanced before you click Finish, and change the "every day" to "every hour."
Thanks for the answer, however I keep getting the following error, --------- The syntax of the command is incorrect. ---------
Here is a copy of the file I used, ---------- @echo off setlocal set LocalFolder=C:\My Documents\Logs set RemoteFile=\\Nas-01\Status\htm\syslog.htm set timestamp=%DATE:/=-%-%TIME:~0,2%%TIME:~3,2% copy %RemoteFile% %LocalFolder%\%timestamp%.* ---------------
Thanks for that, Razor. I keep making the same mistakes when I give code samples to people. Of course, I tested the above and it worked on my machine - but that's because my pathnames did not contain any spaces. As soon as you've got spaces, you need to enclose in quotes. But I keep forgetting.
The information on Computing.Net is the opinions of its users. Such
opinions may not be accurate and they are to be used at your own risk.
Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE