Jump to content

can anyone help with scripts (.bat)

MisterWhite

Can anyone tell me how to create a .bat file, so that every 10mins it would check if a file was updated, and if it was to copy it to another location?
Lets say we have C: hard drive and an IP.text file in a C:\server folder.

i5-4690k, R9 380 4gb, 8gb-1600MHz ram, corsair vs 550w, astrock h97m anniversary.

 

Link to comment
Share on other sites

Link to post
Share on other sites

Backup basically?

i5 4670k @ 4.2GHz (Coolermaster Hyper 212 Evo); ASrock Z87 EXTREME4; 8GB Kingston HyperX Beast DDR3 RAM @ 2133MHz; Asus DirectCU GTX 560; Super Flower Golden King 550 Platinum PSU;1TB Seagate Barracuda;Corsair 200r case. 

Link to comment
Share on other sites

Link to post
Share on other sites

Would a scirpt that only copies a file work? Or does it HAVE to check the file?

Link to comment
Share on other sites

Link to post
Share on other sites

robocopy c:\server\ <destination_path> IP.text /R:1 /W:1

 

 

put that line in a bat file and run it as a scheduled task every 10 minutes.

 

Edit: if there are spaces in your paths, include them in double quotes...

Link to comment
Share on other sites

Link to post
Share on other sites

a .bat file REALLY wasnt made to do that, but if theres a way of checking if the file changed, it shouldnt be too hard.

(you dont actually need to look at the file itself, more so at the "last changed" in the file's metadata.)

 

is the "IP.txt" example you gave the goal for this batchfile? because there may be nicer ways of handling what you're trying to reach.

Link to comment
Share on other sites

Link to post
Share on other sites

Backup basically?

Welll, i guess you can put it that way. But first it should check if it was updated

i5-4690k, R9 380 4gb, 8gb-1600MHz ram, corsair vs 550w, astrock h97m anniversary.

 

Link to comment
Share on other sites

Link to post
Share on other sites

robocopy c:\server\ <destination_path> IP.text /R:1 /W:1

 

 

put that line in a bat file and run it as a scheduled task every 10 minutes.

 

Edit: if there are spaces in your paths, include them in double quotes...

or you could make it "quick and dirty" and make it loop with a 10 minute sleep.

Link to comment
Share on other sites

Link to post
Share on other sites

Welll, i guess you can put it that way. But first it should check if it was updated

 

robocopy c:\server\ <destination_path> IP.text /R:1 /W:1

 

 

put that line in a bat file and run it as a scheduled task every 10 minutes.

 

Edit: if there are spaces in your paths, include them in double quotes...

 

Should also mention, robocopy wont re-copy unless it was updated...

Link to comment
Share on other sites

Link to post
Share on other sites

a .bat file REALLY wasnt made to do that, but if theres a way of checking if the file changed, it shouldnt be too hard.

(you dont actually need to look at the file itself, more so at the "last changed" in the file's metadata.)

 

is the "IP.txt" example you gave the goal for this batchfile? because there may be nicer ways of handling what you're trying to reach.

Well i just learned that .bat can be used to move files, so i thought it can be used like that also. If you know a "nicer" way to copy the file IF it was updated please share :)

i5-4690k, R9 380 4gb, 8gb-1600MHz ram, corsair vs 550w, astrock h97m anniversary.

 

Link to comment
Share on other sites

Link to post
Share on other sites

Can anyone tell me how to create a .bat file, so that every 10mins it would check if a file was updated, and if it was to copy it to another location?

Lets say we have C: hard drive and an IP.text file in a C:\server folder.

you can check if it has been moved, because then it won't be in the original location and it will give an error if you try to read it :)

Link to comment
Share on other sites

Link to post
Share on other sites

Well i just learned that .bat can be used to move files, so i thought it can be used like that also. If you know a "nicer" way to copy the file IF it was updated please share :)

could you give an idea of what you're doing in general here?

 

i'm guessing you have some sort of service that updates the "IP.txt" file with an IP address, and every time it changes you want to copy it over somewhere else.

 

do you want to "log" changes, by having a bunch of IP*.txt files over time, or do you rather just want to make the initial file available in a different location?

Link to comment
Share on other sites

Link to post
Share on other sites

Should also mention, robocopy wont re-copy unless it was updated...

i see you know this stuff. so ok i need a "sleep" comand :D after the  robocopy c:\server\ <destination_path> IP.text /R:1 /W:1 AND an explanation on what does "<destination_path> IP.text /R:1 /W:1" mean.

i5-4690k, R9 380 4gb, 8gb-1600MHz ram, corsair vs 550w, astrock h97m anniversary.

 

Link to comment
Share on other sites

Link to post
Share on other sites

could you give an idea of what you're doing in general here?

 

i'm guessing you have some sort of service that updates the "IP.txt" file with an IP address, and every time it changes you want to copy it over somewhere else.

 

do you want to "log" changes, by having a bunch of IP*.txt files over time, or do you rather just want to make the initial file available in a different location?

Basicaly if the ip address was changed ill need to copy that file so that the content in that ip would be available. Cause if the ip changes and an old ip.text has the wrong ip, it wont show anything.

i5-4690k, R9 380 4gb, 8gb-1600MHz ram, corsair vs 550w, astrock h97m anniversary.

 

Link to comment
Share on other sites

Link to post
Share on other sites

Basicaly if the ip address was changed ill need to copy that file so that the content in that ip would be available. Cause if the ip changes and an old ip.text has the wrong ip, it wont show anything.

but what exactly is the text file used for in its destination location? because if its straight forward for being read by another service, theres better ways of handling this than copying.

Link to comment
Share on other sites

Link to post
Share on other sites

but what exactly is the text file used for in its destination location? because if its straight forward for being read by another service, theres better ways of handling this than copying.

firstly im going step by step to a big command.

I'll have a ip.txt file. Users will have channel names lets say BBC. They will "log in" and will ask the ip.txt for an ip address of this channels stream location. SO if the "provider" changes the IP of "BBC", ill need to "update" by copying the file.

i5-4690k, R9 380 4gb, 8gb-1600MHz ram, corsair vs 550w, astrock h97m anniversary.

 

Link to comment
Share on other sites

Link to post
Share on other sites

i see you know this stuff. so ok i need a "sleep" comand :D after the  robocopy c:\server\ <destination_path> IP.text /R:1 /W:1 AND an explanation on what does "<destination_path> IP.text /R:1 /W:1" mean.

<destination_path> is where you want the file to be copied to.

'IP.text' is the name of the file you are copying (in this case, the one in your example). You can also use /E to copy everything in a directory.

/R:1 - retry one time on copy failure

/W:1 - wait one second on copy failure before retry

 

again, i'd suggest using a scheduled task to run this command every 10 minutes rather than a looping batch file. If you must do a loop, try this (replacing the bracketed statements with your desired directories and files):

 

:start

robocopy "<source_path>" "<destination_path>" "<filename_to_copy>" /R:1 /W:1

sleep 600

goto start

Link to comment
Share on other sites

Link to post
Share on other sites

<destination_path> is where you want the file to be copied to.

'IP.text' is the name of the file you are copying (in this case, the one in your example). You can also use /E to copy everything in a directory.

/R:1 - retry one time on copy failure

/W:1 - wait one second on copy failure before retry

 

again, i'd suggest using a scheduled task to run this command every 10 minutes rather than a looping batch file. If you must do a loop, try this (replacing the bracketed statements with your desired directories and files):

 

:start

robocopy "<source_path>" "<destination_path>" "<filename_to_copy>" /R:1 /W:1

sleep 600

goto start

In the windows scheduler there is no option to select BY MINUTES. only daily and other not suitable ways

i5-4690k, R9 380 4gb, 8gb-1600MHz ram, corsair vs 550w, astrock h97m anniversary.

 

Link to comment
Share on other sites

Link to post
Share on other sites

In the windows scheduler there is no option to select BY MINUTES. only daily and other not suitable ways

 

1zw1d9l.png

 

What version of windows are you using?

Link to comment
Share on other sites

Link to post
Share on other sites

1zw1d9l.png

 

What version of windows are you using?

Windows 10. When i create a basic task i only get to choose one time

EDIT: i dont have advanced options

EDIT:2 woop. i need to create a task, not a BASIC task

i5-4690k, R9 380 4gb, 8gb-1600MHz ram, corsair vs 550w, astrock h97m anniversary.

 

Link to comment
Share on other sites

Link to post
Share on other sites

<destination_path> is where you want the file to be copied to.

'IP.text' is the name of the file you are copying (in this case, the one in your example). You can also use /E to copy everything in a directory.

/R:1 - retry one time on copy failure

/W:1 - wait one second on copy failure before retry

 

again, i'd suggest using a scheduled task to run this command every 10 minutes rather than a looping batch file. If you must do a loop, try this (replacing the bracketed statements with your desired directories and files):

 

:start

robocopy "<source_path>" "<destination_path>" "<filename_to_copy>" /R:1 /W:1

sleep 600

goto start

Hey dude, can you help with another question?

i5-4690k, R9 380 4gb, 8gb-1600MHz ram, corsair vs 550w, astrock h97m anniversary.

 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×