hi everyone,
I'm searching to do a functionally bash script for copy many file inside in a directory the scenario is:
root path= /var/www/clients/ inside of this there are many subdirectories with this name: client1 to x (depends of the customer) it happens that a customer not renew the contract and I would stopping to do a backup directory for him.
this operation should be versatile and very easy so, I don't understand the error in this script. look below:
!/bin/bash
while read line; do read NR PATH NAME<<<$(IFS=" "; echo $line)
cd /var/www/clients/ cp -R $PATH /backup/temp/www/ cd /backup/temp/www/
tar cfz `date +%F`_$NAME.tar.gz web$NR/ mv *.tar.gz /backup/www/test/ rm -rf /backup/temp/www/*
done < sites.txt
anyone can help me, please? thanks in advance
regards
Hi you are overwriting the PATH env variable. change PATH to CLIPATH and all will work
On Sun, May 25, 2014 at 12:08 PM, Paolo De Michele paolo@paolodemichele.itwrote:
hi everyone,
I'm searching to do a functionally bash script for copy many file inside in a directory the scenario is:
root path= /var/www/clients/ inside of this there are many subdirectories with this name: client1 to x (depends of the customer) it happens that a customer not renew the contract and I would stopping to do a backup directory for him.
this operation should be versatile and very easy so, I don't understand the error in this script. look below:
!/bin/bash
while read line; do read NR PATH NAME<<<$(IFS=" "; echo $line)
cd /var/www/clients/ cp -R $PATH /backup/temp/www/ cd /backup/temp/www/ tar cfz `date +%F`_$NAME.tar.gz web$NR/ mv *.tar.gz /backup/www/test/ rm -rf /backup/temp/www/*
done < sites.txt
anyone can help me, please? thanks in advance
regards _______________________________________________ CentOS mailing list CentOS@centos.org http://lists.centos.org/mailman/listinfo/centos
Hi,
I don't understand the procedure so, in theory the path should be /var/www/clients/client* (I have number from 1 to X) I replaced the PATH in read section
It's correct?
On 05/26/2014 11:12 AM, Alberto Varesio wrote:
Hi you are overwriting the PATH env variable. change PATH to CLIPATH and all will work
On Sun, May 25, 2014 at 12:08 PM, Paolo De Michele paolo@paolodemichele.itwrote:
hi everyone,
I'm searching to do a functionally bash script for copy many file inside in a directory the scenario is:
root path= /var/www/clients/ inside of this there are many subdirectories with this name: client1 to x (depends of the customer) it happens that a customer not renew the contract and I would stopping to do a backup directory for him.
this operation should be versatile and very easy so, I don't understand the error in this script. look below:
!/bin/bash
while read line; do read NR PATH NAME<<<$(IFS=" "; echo $line)
cd /var/www/clients/ cp -R $PATH /backup/temp/www/ cd /backup/temp/www/ tar cfz `date +%F`_$NAME.tar.gz web$NR/ mv *.tar.gz /backup/www/test/ rm -rf /backup/temp/www/*
done < sites.txt
anyone can help me, please? thanks in advance
regards _______________________________________________ CentOS mailing list CentOS@centos.org http://lists.centos.org/mailman/listinfo/centos
On 26 May 2014 @09:12 zulu, Alberto Varesio wrote:
you are overwriting the PATH env variable. change PATH to CLIPATH and all will work
I don't understand, too... do you mean the script should read
!/bin/bash
while read line; do read NR CLIPATH NAME<<<$(IFS=" "; echo $line)
cd /var/www/clients/ cp -R $CLIPATH /backup/temp/www/ cd /backup/temp/www/
tar cfz `date +%F`_$NAME.tar.gz web$NR/ mv *.tar.gz /backup/www/test/ rm -rf /backup/temp/www/*
done < sites.txt
instead? /i.e./ replace **all** instances of "PATH" with "CLIPATH" ?
Yes!
PATH should be a reserved name, NOT to be used as a variable in scripts.
btw, what errors do you get running the script ?
On Tue, May 27, 2014 at 11:44 PM, Darr247 darr247@gmail.com wrote:
On 26 May 2014 @09:12 zulu, Alberto Varesio wrote:
you are overwriting the PATH env variable. change PATH to CLIPATH and all will work
I don't understand, too... do you mean the script should read
!/bin/bash
while read line; do read NR CLIPATH NAME<<<$(IFS=" "; echo $line)
cd /var/www/clients/ cp -R $CLIPATH /backup/temp/www/ cd /backup/temp/www/ tar cfz `date +%F`_$NAME.tar.gz web$NR/ mv *.tar.gz /backup/www/test/ rm -rf /backup/temp/www/*
done < sites.txt
instead? /i.e./ replace **all** instances of "PATH" with "CLIPATH" ? _______________________________________________ CentOS mailing list CentOS@centos.org http://lists.centos.org/mailman/listinfo/centos
On 2014-05-25 12:08, Paolo De Michele wrote:> !/bin/bash
while read line; do read NR PATH NAME<<<$(IFS=" "; echo $line)
cd /var/www/clients/ cp -R $PATH /backup/temp/www/ cd /backup/temp/www/ tar cfz `date +%F`_$NAME.tar.gz web$NR/ mv *.tar.gz /backup/www/test/ rm -rf /backup/temp/www/*
done < sites.txt
A few things:
1. A shebang is two chars, "#!", not just an exclamation point. (possibly just a typo / copy error)
2. $PATH is special, use something else (e.g. $path).
3. Your `tar` stanza is wrong (if it's not obvious to you why that is, now is a good time to make a habit of using long options (e.g. `--gzip`) whenever possible).
4. Always quote variables that could possibly have whitespace in them ($NAME in this case).
What is it you're trying to accomplish with the IFS and echo? Why not just
while read nr path name; do : stuff goes here done
Elias Persson wrote:
On 2014-05-25 12:08, Paolo De Michele wrote:> !/bin/bash
while read line; do read NR PATH NAME<<<$(IFS=" "; echo $line)
cd /var/www/clients/ cp -R $PATH /backup/temp/www/ cd /backup/temp/www/ tar cfz `date +%F`_$NAME.tar.gz web$NR/ mv *.tar.gz /backup/www/test/ rm -rf /backup/temp/www/*
done < sites.txt
Dumb question: why not while read line; do read NR PATH NAME<<<$(IFS=" "; echo $line) cd /var/www/clients/ tar -czf /backup/www/test/`date +%F`_$NAME.tar.gz web$NR/ done < sites.txt
A few things:
<snip>
- Your `tar` stanza is wrong (if it's not obvious to you why that is, now is a good time to make a habit of using long options (e.g. `--gzip`) whenever possible).
Why long? <snip> mark
On 2014-05-28 15:35, m.roth@5-cent.us wrote:
Elias Persson wrote:
On 2014-05-25 12:08, Paolo De Michele wrote:> !/bin/bash
<snip>
tar cfz `date +%F`_$NAME.tar.gz web$NR/
<snip>
Dumb question: why not
<snip>
tar -czf /backup/www/test/`date +%F`_$NAME.tar.gz web$NR/
<snip>
A few things:
<snip> > 3. Your `tar` stanza is wrong (if it's not obvious to you why that is, > now is a good time to make a habit of using long options > (e.g. `--gzip`) whenever possible).
Why long?
<snip> mark
With long options one can't stick something that takes an argument in the middle of a bunch of others (which was the error I thought was present here, and would have been the case if your example had the options in the same order). It's also more readily apparent what the options do, though that's not much of an issue for common things like tar or rm. I for one can never recall if it's -c or -C that's --reuse-message for git commit.
Elias Persson wrote:
On 2014-05-28 15:35, m.roth@5-cent.us wrote:
Elias Persson wrote:
On 2014-05-25 12:08, Paolo De Michele wrote:> !/bin/bash
<snip> >>> tar cfz `date +%F`_$NAME.tar.gz web$NR/ <snip> >> > Dumb question: why not <snip> > tar -czf /backup/www/test/`date +%F`_$NAME.tar.gz web$NR/
<snip>
Why long?
<snip>
With long options one can't stick something that takes an argument in the middle of a bunch of others (which was the error I thought was present here, and would have been the case if your example had the options in the same order). It's also more readily apparent what the options do, though that's not much of an issue for common things like tar or rm. I for one can never recall if it's -c or -C that's --reuse-message for git commit.
<shrug> Everybody I know knows the short flags.
However, the point I made in the code snippet was, why copy it to a temp directory, then tar and compress it, then copy it to another directory, then remove the copy in the temp directory, rather than just tar and compress it directly to the target directory? I *did* give the full path the the target, preceding the final filename.
mark
On 05/28/2014 07:10 AM, Elias Persson wrote:
On 2014-05-25 12:08, Paolo De Michele wrote:> !/bin/bash
tar cfz `date +%F`_$NAME.tar.gz web$NR/
- Your `tar` stanza is wrong (if it's not obvious to you why that is, now is a good time to make a habit of using long options (e.g. `--gzip`) whenever possible).
Actually it is correct, aside from possible whitespace issues with $NAME. It is using an outdated syntax (short options all in a group _without_ a leading "-"), but doing it correctly with the needed option argument following the set of option letters.
On 2014-05-28 15:40, Robert Nichols wrote:
On 05/28/2014 07:10 AM, Elias Persson wrote:
On 2014-05-25 12:08, Paolo De Michele wrote:> !/bin/bash
tar cfz `date +%F`_$NAME.tar.gz web$NR/
- Your `tar` stanza is wrong (if it's not obvious to you why that is, now is a good time to make a habit of using long options (e.g. `--gzip`) whenever possible).
Actually it is correct, aside from possible whitespace issues with $NAME. It is using an outdated syntax (short options all in a group _without_ a leading "-"), but doing it correctly with the needed option argument following the set of option letters.
I stand corrected. Apparently having the "f" in the middle is not a problem with the old syntax.
On 05/28/2014 09:58 AM, Elias Persson wrote:
On 2014-05-28 15:40, Robert Nichols wrote:
On 05/28/2014 07:10 AM, Elias Persson wrote:
On 2014-05-25 12:08, Paolo De Michele wrote:> !/bin/bash > tar cfz `date +%F`_$NAME.tar.gz web$NR/
- Your `tar` stanza is wrong (if it's not obvious to you why that is, now is a good time to make a habit of using long options (e.g. `--gzip`) whenever possible).
Actually it is correct, aside from possible whitespace issues with $NAME. It is using an outdated syntax (short options all in a group _without_ a leading "-"), but doing it correctly with the needed option argument following the set of option letters.
I stand corrected. Apparently having the "f" in the middle is not a problem with the old syntax.
It's analogous to printf(), where a string with all the format controls comes first, followed by all of the needed arguments in the needed sequence. It causes all sorts of weirdness when you get things wrong, as when unquoted whitespace causes what should have been one argument to appear as two or more.