我写了以下代码:
#!/bin/bash
trap 'echo "Hey your are interupting the program"' SIGINT
#function cleanup()
#{
# echo "Cleanup called"
# rm -rf /root/summary_command.log
# rm -rf /root/summary_command.log
#}
#trap 'cleanup ; exit 1' EXIT SIGINT SIGILL SIGHUP
cluster_name="$(cat /home/enterprisedb/.bash_profile |grep PGCLUSTER|awk '{print $1}'|cut -d '=' -f2|cut -d ';' -f1)"
echo "$cluster_name"
wal_count=$(ls /var/lib/edb/as10/data/pg_wal/ | wc -l)
echo "$wal_count"
size_count=$(du -h /var/lib/edb/as10/data/pg_wal/|awk '{print $1}'|tail -1)
wal_size_count=$(du -sk /var/lib/edb/as10/data/pg_wal/ | awk '{ total = total + $1 } END { print total/1024**2 }')
echo "$wal_size_count"
echo "$size_count"
if [ $wal_count > 20 -a $wal_size_count < 11.0 ]; then
echo "All working fine"
top_file=$(expr $wal_count - 1)
echo "$top_file"
original_file=$(ls -lrth /var/lib/edb/as10/data/pg_wal/ |awk '{print $9}'|head -n "$top_file"|tr -d "[:space:]")
echo "$original_file"
su - enterprisedb << EOF
#cp /var/lib/edb/as10/data/pg_wal/"$original_file" /u03/app/postgres/archivelog/"$cluster_name"/
EOF
else
echo "Not working fine"
fi
if语句附近出现错误。
仅if
部分无效。我也尝试过((...))
和[[...]]
。