Reputation: 4072
For example:
#!/bin/bash
DATABASES=`ssh root@host "mysql -u root -e 'show databases;'"`;
for database in $(echo $DATABASES | tr ";" "\n")
do
if [ "$database" -ne "information_schema" ]
then
# ssh root@host "mysqldump -u root ..."
# rsync ...
fi
done
Need exclude:
How to make 3 conditions in one "if"? in other languages use "or" or "||" but in bash is?
Upvotes: 2
Views: 45
Reputation: 124646
Inside [[ ... ]]
you can use ||
for OR and &&
for AND conditions, for example:
if [[ $database != information_schema && $database != sys && $database != Database ]]
then
# ssh root@host "mysqldump -u root ..."
# rsync ...
fi
Another alternative is using a case
:
case "$database" in
information_schema|sys|Database) ;;
*)
# ssh root@host "mysqldump -u root ..."
# rsync ...
;;
esac
Upvotes: 1
Reputation: 785058
In BASH you can use @(str1|str2|str3)
inside [[...]]
to compare against multiple string values:
if [[ $database != @(information_schema|Database|sys) ]]; then
echo "execute ssh command"
fi
Upvotes: 2