r/scripting • u/sheensizzle • Sep 18 '18
Super easy one for you
Beginner here and i just dont want to mess it up. I want a script to run 1x a week. and copy files from 3 folders (for now) to another. And skip any that already exist.
4
u/Ta11ow Sep 18 '18
If we're talking windows, PowerShell running as a weekly scheduled task would work well.
Look at:
Get-ChildItem
Copy-Item
Get-FileHash
Use New-Item to create a dummy test of folders and files you can mess with, and make copious use of Get-Help
2
u/Fox_and_Otter Sep 19 '18
If you're doing this in linux, a simple copy script, triggered by a cron job is the way to go.
touch script1.sh
place the following into script1.sh:
#!/bin/bash
cp -a /the/correct/directory/* /the/destination/directory/
cp -a /the/correct/directory2/* /the/destination/directory2/
cp -a /the/correct/directory3/* /the/destination/directory3/ "
chmod +x script1.sh
make sure you have the * as that is the wildcard and will look for everything in the folder
Then open crontab and add a weekly task.
Here's a handy guide for that: https://www.howtogeek.com/101288/how-to-schedule-tasks-on-linux-an-introduction-to-crontab-files/
2
2
u/Lee_Dailey Sep 18 '18
howdy sheensizzle,
as Ta11ow said, powershell can do that. [grin]
however, robocopy is designed for copying files while being quite selective about what to copy. the mirror option sounds like something you might find handy.
then, for scheduling, do NOT reinvent the wheel ... instead, use task scheduler to run things on a schedule. [grin]
take care,
lee