bash script reading directory with while and do

Normand Marion normand.marion at gmail.com
Sun May 25 18:25:04 UTC 2014


In your tar command put your "f" parameter close to your file name and use
the "-":

tar -Zcf file.tar.gz directory

Also I think that your script can be well improved by replacing all your
cd, cp, mv, rm commands with the corresponding features of the tar command.

Although using `date "+%F"` is not an error it could be improved by $(date
+%F) a modern way of using an inbeded command

I hope that will help you.


2014-05-25 6:09 GMT-04:00 Paolo De Michele <paolo at paolodemichele.it>:

> 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
>
> --
> ubuntu-users mailing list
> ubuntu-users at lists.ubuntu.com
> Modify settings or unsubscribe at:
> https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
>



-- 
*Normand Marion*

normand.marion at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20140525/1e7d996d/attachment.html>


More information about the ubuntu-users mailing list