1

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?

DISMFA
  • 33

1 Answers1

1
find "/root/backups/dbback_$date/" -type f -name "${search}*.sql.gz" -not -path '*livefiles*' | while IFS= read -r 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

Now works

DISMFA
  • 33