P
P
popopa2018-08-27 10:14:43
linux
popopa, 2018-08-27 10:14:43

How to make an array for find command path?

Greetings!
There is the following code which does something with the found images.

DIR="/var/www/subdomain.example.com/upload/" 
STORAGE="gs://images.example.com/" #storage on google cloud
LIST="logs/urls.txt"


######################################################################
######################################################################
######################################################################
######################################################################
DIR_FROM_EXECUTED="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"

if ;    then
        mkdir -p "$DIR_FROM_EXECUTED/logs/"
fi


> "$DIR_FROM_EXECUTED/logs/urls.txt"
> "$DIR_FROM_EXECUTED/logs/lastlog.txt"



find "$DIR" -regextype posix-extended -iregex ".*\.(png|jpg|gif|jpeg|ico|svg)" -not -path "${DIR}tmp/*" -print > "$LIST" 



 while read URL
do
    URLTOUPLOAD=$(echo $STORAGE$URL | sed "[email protected]${DIR}@@g")
        gsutil -m cp "$URL" "$URLTOUPLOAD"  > /dev/null 2>&1    
        echo  "$URL" "=>"  "$URLTOUPLOAD" | sed "[email protected]:@https:@g" | tee -a "$DIR_FROM_EXECUTED/logs/lastlog.txt"
        gsutil -m acl ch -u AllUsers:R "$URLTOUPLOAD" > /dev/null 2>&1
        gsutil -m setmeta -h "Cache-Control:public, max-age=31536000" "$URLTOUPLOAD" > /dev/null 2>&1
        rm -f "$URL" > /dev/null 2>&1
done < $LIST

But it is necessary that the DIR variable be not one statistical path, but for the next command, that is, for all found server_names.
grep -rl "server_name " /etc/nginx/conf.d/ | sed '/default/d' | sed '/sclool.tools/d' | sed '/images.interatletika/d' | sed 's/.conf//g' | sed 's/\/etc\/nginx.d\//\/var\/www\//g

What is the best way to do this, again through for do done?
Or? Can I have examples?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Victor Taran, 2018-08-27
@popopa

for i in `mysql -uroot -pPass -e'show databases;' | grep -v information_schema | grep -v Database`; do mysqldump -uroot -pDungeonKeeper $i > /var/backup/mysql/last/$i.sql;done >> /dev/null 2>> /var/log/sqlbackup.log
tar -czvf /var/backup/mysql/`date +%Y`/sqldump-`date +%Y-%m-%u`.tar.gz ./last >> /dev/null > /var/log/sqlbackup.log

the loop and the variable is substituted anywhere.
In this case, we look at the names of the databases and archive them in a loop.
you can improve

S
Saboteur, 2018-08-27
@saboteur_kiev

It is possible so to try, only $LIST It is necessary to nullify.

grep -rl "server_name " /etc/nginx/conf.d/ | sed '/default/d' | sed '/sclool.tools/d' | sed '/images.interatletika/d' | \ sed 's/.conf//g' | sed 's/\/etc\/nginx.d\//\/var\/www\//g | \
xargs find {} -regextype posix-extended -iregex ".*\.(png|jpg|gif|jpeg|ico|svg)" -not -path "${DIR}tmp/*" -print >> "$LIST" \;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question