Results 1 to 2 of 2
Greetings all, im trying to write a script to check for the presence of an "update" folder, and then if its present, take files from that "update folder" and placing ...
- 03-06-2009 #1Just Joined!
- Join Date
- Mar 2009
- Posts
- 3
scripting to check for update folder
Greetings all, im trying to write a script to check for the presence of an "update" folder, and then if its present, take files from that "update folder" and placing them in their respective folders...
Psuedo Code
Code:Print Output checking for updates If updates folder exists in folder 1 then Print Updates Found Print Updating Current Folder copy file from /folder1/updates to /folder2/current end ifBeing the noob that I am (first day writing linux), Im assuming my above code seems logical. However, where the "???" exists is what Im having trouble with.Code:#!/bin/sh echo "Checking for Updates" if [ -d /folder1/Updates ] then echo "Updates Found" echo "Updating Current Folder ??? fi
Any assistance would be greatly appreciated.
Regards,
T
- 03-06-2009 #2
A basic solution would look something like this:
The command cp -u would copy the files in the Update directory to the root / directory only if they are newer than a file by the same name in the destination folder.Code:#!/bin/sh echo "Checking for Updates" if [ -d /folder1/Updates ] then echo "Updates Found" echo "Updating Current Folder" cp -u /folder1/Updates/* / else echo "No Update directory found in /folder1/" fi exit 0
Alternatively, you could also instantiate a loop that would test the presence of the destination directory just as you have for the /folder/Updates directory and then add a nestedbefore then using the cp -u command.Code:[ -f /<destination dir>/<filename> ]
Also, if you are really wanting to copy the said files to the root directory, user validation would be in order to check if the user is root, or a sudo user.
It all depends on just how much validation you need. I would consider a larger script to validate if the files are really at root.


Reply With Quote