我正在尝试编写一个脚本来备份由应用程序管理的数据库,并想知道是否有更简单的方法来执行它。我想我正在努力实现复杂化。
基本上我正在停止应用程序服务(除了数据库)并将其保存到文本文件中,直到它提供适当的输出才会被读取。然后,我运行一个脚本,将数据库导出到两个文件,并将输出写入另一个文本文件,该文件将被读取,直到成功为止。然后,我再次启动服务。
以下是代码:
#!/bin/bash
#Make sure to run in the right folder!
echo "Here it will stop the manager services"
/etc/init.d/arcsight_services stop manager > /tmp/tmp/mangerstatusdown.txt
while [["./rr.sh /tmp/tmp/managerstatusdown.txt" != "[manager status down]"]]
do
echo "Not Ready Yet"
read -p "Do you think it's ready to move on?"
done
echo "Now it will export the database"
/opt/arcsight/manager/bin/arcsight export_system_tables > /tmp/tmp/systemtables.txt
while [["./rr.sh /tmp/tmp/systemtables.txt" != "[system tables export successful]" ]]
do
echo "Not Ready Yet"
read -p "Do you think it's ready to move on?"
done
echo "Here it will start the manager again"
/etc/init.d/arcsight_services start manager
这是引用的rr.sh脚本:
while IFS=' ' read -r line || [[ -n "$line"]]; do
echo "Text read from file: $line"
done < "$1"
#run as follows:
#chmod +x rr.sh
#./rr.sh filename.txt
这实际上是我的第一个脚本,所以在你解释时请记住这一点!
答案 0 :(得分:0)
bash
没有直接进行字符串比较;你需要使用特定的命令。
while [[ "$(./rr.sh /tmp/tmp/systemtables.txt)" != "[system tables export successful]" ]]
do