I have this bash script, but it doesn't seem to work at the 'find' point.
#!/bin/bash
echo 'What date YYYY-MM-DD format?'
read date
echo "starting restore script..."
echo "Looking in /root/backups/dbback_$date/"
cd "/root/backups/dbback_$date/"
echo 'What search term for files?'
read search
echo 'What database am I restoring too?'
read database
count=`ls -l | grep "$search" | wc -l`
echo "$count files found containing $search"
find "/root/backups/dbback_$date/" -type f -name '$search*.sql.gz' -not -path '*livefiles*' | while read file; do
echo "$file is being restored"
gunzip < "$file" | mysql -u root -p* '$database';
echo "$file has been restored...moving on to next file."
done
Between the find and the done - nothing happens, the last echo I get is
9 files found containing test
Please can anyone advise if I am doing something wrong?
'$search*.sql.gz'
the shell will not expand$search
because of the surrounding single quotesread
.paths must precede expression:
| while IFS= read -r line; do
*
inside quotes to prevent the shell from expanding that ex.$search'*.sql.gz'
or use double quotes"$search*.sql.gz"