mitanc
March 20th, 2012, 11:28 AM
Hey All,
I need help with a script to find new files and put copy them recursively in a directory and after its done, to log into an ftp and upload them.
For the new files aspect, I am using a program called cpafter.sh (http://movingtofreedom.org/2007/04/15/bash-shell-script-copy-only-files-modified-after-specified-date/). This program allows one to search a directory and all its sub-directories and copy directories along with any files modified after a certain date.
In my script I am trying to create a master folder where the files will copy too. The folder will be called ZILVER_<YYYYMMDD> where that would be the date filled in.
After the folder name is made, I would copy all files newer than one day before the current date.
This is what I got so far:
#!/bin/bash
# Program to copy Zilver Zoom Files
# Author: Mitan Chandihok
# Set initial Variable
FILE='/ldaphome/WorkFiles/Customers/ZILVERZOOM/PRDOUCTIONPHOTOS/'
td=`date +%Y%m%d`
oldd=$(date -d "-1 days" +%Y%m%d)
# Copy everything modified after yesterday to this folder
echo `echo sh /usr/local/bin/cpafter.sh -vf -a $oldd -s $FILE -t ./test_ZILVER/ZilverPhoto_$td/`
echo `sh /usr/local/bin/cpafter.sh -vf -a $oldd -s $FILE -t ./test_ZILVER/ZilverPhoto_$td/`
The Output of running this looks like:
sysadmin@dc01-lg:~/TEST$ sh zilver.sh
sh /usr/local/bin/cpafter.sh -vf -a 20120319 -s /ldaphome/WorkFiles/Customers/ZILVERZOOM/PRDOUCTIONPHOTOS/ -t ./test_ZILVER/ZilverPhoto_20120320/
/usr/local/bin/cpafter.sh: 24: usage+=to target dir, creating any subdirectories as needed.\n\n: not found
/usr/local/bin/cpafter.sh: 25: usage+=\tusage: cpafter.sh [-vf] -a after_date_YYYYMMDD -s source_dir -t target_dir\n: not found
/usr/local/bin/cpafter.sh: 26: usage+=\t\t-v verbose\n: not found
/usr/local/bin/cpafter.sh: 27: usage+=\t\t-f force target dir creation or copying to non-empty target dir\n: not found
/usr/local/bin/cpafter.sh: 46: [[: not found
/usr/local/bin/cpafter.sh: 46: -z: not found
/usr/local/bin/cpafter.sh: 46: -z: not found
/usr/local/bin/cpafter.sh: 46: 0: not found
/usr/local/bin/cpafter.sh: 51: [[: not found
/usr/local/bin/cpafter.sh: 63: [[: not found
/usr/local/bin/cpafter.sh: 70: [[: not found
/usr/local/bin/cpafter.sh: 74: [[: not found
/usr/local/bin/cpafter.sh: 84: cannot open 20120319: No such file
/usr/local/bin/cpafter.sh: 84: 20120320: not found
cd: 98: can't cd to ./test_ZILVER/ZilverPhoto_20120320/
cd: 102: can't cd to /ldaphome/WorkFiles/Customers/ZILVERZOOM/PRDOUCTIONPHOTOS/
/usr/local/bin/cpafter.sh: 106: [[: not found
cp: `/home/sysadmin/TEST/./zilver.sh' and `/home/sysadmin/TEST/./zilver.sh' are the same file
./zilver.sh
sysadmin@dc01-lg:~/TEST$
What I don't get is if I copy and paste the command, it runs fine from the terminal.
I need help with this, and then any advice on the best way to login to an ftp and upload the directory. Since its by date and will run once every night, I don't see any conflicts.
Thanks for the help!
3/20/2012
Hey, I realized I spelled the directory wrong when I set the variable, so I got this working. Can anyone help me out with figuring out how to upload this new folder to an FTP?
Thanks!
I need help with a script to find new files and put copy them recursively in a directory and after its done, to log into an ftp and upload them.
For the new files aspect, I am using a program called cpafter.sh (http://movingtofreedom.org/2007/04/15/bash-shell-script-copy-only-files-modified-after-specified-date/). This program allows one to search a directory and all its sub-directories and copy directories along with any files modified after a certain date.
In my script I am trying to create a master folder where the files will copy too. The folder will be called ZILVER_<YYYYMMDD> where that would be the date filled in.
After the folder name is made, I would copy all files newer than one day before the current date.
This is what I got so far:
#!/bin/bash
# Program to copy Zilver Zoom Files
# Author: Mitan Chandihok
# Set initial Variable
FILE='/ldaphome/WorkFiles/Customers/ZILVERZOOM/PRDOUCTIONPHOTOS/'
td=`date +%Y%m%d`
oldd=$(date -d "-1 days" +%Y%m%d)
# Copy everything modified after yesterday to this folder
echo `echo sh /usr/local/bin/cpafter.sh -vf -a $oldd -s $FILE -t ./test_ZILVER/ZilverPhoto_$td/`
echo `sh /usr/local/bin/cpafter.sh -vf -a $oldd -s $FILE -t ./test_ZILVER/ZilverPhoto_$td/`
The Output of running this looks like:
sysadmin@dc01-lg:~/TEST$ sh zilver.sh
sh /usr/local/bin/cpafter.sh -vf -a 20120319 -s /ldaphome/WorkFiles/Customers/ZILVERZOOM/PRDOUCTIONPHOTOS/ -t ./test_ZILVER/ZilverPhoto_20120320/
/usr/local/bin/cpafter.sh: 24: usage+=to target dir, creating any subdirectories as needed.\n\n: not found
/usr/local/bin/cpafter.sh: 25: usage+=\tusage: cpafter.sh [-vf] -a after_date_YYYYMMDD -s source_dir -t target_dir\n: not found
/usr/local/bin/cpafter.sh: 26: usage+=\t\t-v verbose\n: not found
/usr/local/bin/cpafter.sh: 27: usage+=\t\t-f force target dir creation or copying to non-empty target dir\n: not found
/usr/local/bin/cpafter.sh: 46: [[: not found
/usr/local/bin/cpafter.sh: 46: -z: not found
/usr/local/bin/cpafter.sh: 46: -z: not found
/usr/local/bin/cpafter.sh: 46: 0: not found
/usr/local/bin/cpafter.sh: 51: [[: not found
/usr/local/bin/cpafter.sh: 63: [[: not found
/usr/local/bin/cpafter.sh: 70: [[: not found
/usr/local/bin/cpafter.sh: 74: [[: not found
/usr/local/bin/cpafter.sh: 84: cannot open 20120319: No such file
/usr/local/bin/cpafter.sh: 84: 20120320: not found
cd: 98: can't cd to ./test_ZILVER/ZilverPhoto_20120320/
cd: 102: can't cd to /ldaphome/WorkFiles/Customers/ZILVERZOOM/PRDOUCTIONPHOTOS/
/usr/local/bin/cpafter.sh: 106: [[: not found
cp: `/home/sysadmin/TEST/./zilver.sh' and `/home/sysadmin/TEST/./zilver.sh' are the same file
./zilver.sh
sysadmin@dc01-lg:~/TEST$
What I don't get is if I copy and paste the command, it runs fine from the terminal.
I need help with this, and then any advice on the best way to login to an ftp and upload the directory. Since its by date and will run once every night, I don't see any conflicts.
Thanks for the help!
3/20/2012
Hey, I realized I spelled the directory wrong when I set the variable, so I got this working. Can anyone help me out with figuring out how to upload this new folder to an FTP?
Thanks!