bash - script to compress user files via searching through folders for certain folder name -
i'm writing function 1 of programs need search through number of folders until find folder called "userfiles" tar folder giving filename of folder found in. below approach best way go?
compress(){ name=$(cat $user_home/server.txt | sed -e "s/ //g") users=/var/www/home/user/area/*/*/*/ ids=${pwd##*/} # apache logs tar -zcvf logs-$name.tar.gz /var/log/apache2 # user logs in $users; if [ ! -d "userfiles" ]; tar -zcvf userfiles-$name-"$ids".tar.gz $users fi done; # linux logs tar -zcvf linux-logs-$name.tar.gz /var/log/auth.log* /var/log/syslog* /var/log/kern.log* /var/log/mail.log* }
this code:
for in $users; if [ ! -d "userfiles" ]; tar -zcvf userfiles-$name-"$ids".tar.gz $users fi done;
won't described should do. instead, if folder userfiles
not exist in current working directory, tar all user folders multiple times.
try this:
for d in $users; if [ -d "${d}userfiles" ]; tar -zcvf "userfiles-$name-$ids.tar.gz" "${d}userfiles" fi done
Comments
Post a Comment