我正在尝试在BASH中编写脚本,但我遇到了问题。我是脚本新手,所以我打赌有一些愚蠢的错误。
当我尝试运行脚本时 - 我收到错误:
gawk: line:4: while (cmd | readline | {
gawk: line:4: ^ syntax error
gawk: line:11: while (cmd | readline | {
gawk: line:11: ^ syntax error
有谁知道我该如何解决?我究竟做错了什么?对不起我的英语,如果不清楚的话 - 我会尝试解释。
#!/bin/bash
# Description: Script which stores required informations about databases.
# ALGORITHM
# 1. We charge informations from database about known databases (defined in the database system.know_databases).
# 2. We charge informations about actually existing databases.
# 3. We compare the actual values of the declared and print out a message when size of database is too big or there is no declared informations.
cd /var/lib/mysql || exit 1
gawk '
BEGIN {
# login and password declared in .my.cnf
cmd = "mysql -e \"SELECT name, volume, date, description FROM test.database\""
while ( cmd | readline ) {
DATABASE[$1,1] = $2;
DATABASE[$1,2] = $3;
}
close(cmd)
cmd = "find /var/lib/mysql/ -type d -maxdepth 1 -mindepth 1 | xargs du -sm"
while ( cmd | readline ) {
VOL = $1;
NAM = $2;
if ( ! DATABASE[NAM,1] ) {
print "There is no declared informations about " NAM " in table test.database"
continue
}
if ( VOL > DATABASE[NAM,1] ) {
print "Database " NAM " have too big actual size (" VOL "), it exceeds declared sizey in table test.database"
continue
}
}
close(cmd)
}
" /dev/null