<分区>
早上好!我正在尝试使工作中的某些事情自动化。因此,在一个 informix 框中,运行命令“onstat -g dri”,它会给出以下输出(通常):
root@us32999s5000d0a:/root # onstat -g dri
IBM Informix Dynamic Server Version 12.10.FC7W1XPAEE -- On-Line -- Up 39 days 22:56:20 -- 8688044 Kbytes
Data Replication at 0x56b17028:
Type State Paired server Last DR CKPT (id/pg) Supports Proxy Writes
standard off -1 / -1 NA
DRINTERVAL 30
DRTIMEOUT 30
DRAUTO 0
DRLOSTFOUND /usr/informix_engine/etc/dr.lostfound
DRIDXAUTO 1
ENCRYPT_HDR 0
Backlog 0
我的问题是,如何才能在“状态”下 grep ONLY for on or off? 我的问题是,当我使用 cut 尝试隔离开或关时,出现错误:
./AutoDoc.sh: line 27: } | /usr/bin/cut -c1-2": No such file or directory
这是我的脚本,因此您可以准确地看到我在做什么:
#!/bin/bash
export LANG="C"
######## Written by Blake Smreker | b0s00dg | BSmreker@walmart.com ####
######## The goal of this script is to automate DR tickets ############
#Asks for DC number to be used later
printf "What is the four digit DC number?"
read DC
#Asks for 2 lowercase digit country code
printf "What is the two digit lowercase country code?"
read cc
#Defines dsinfx naming convention
infmx=$"dsinfmx.s${DC}.${cc}"
#Defines a variable to call upon the command for DR
onstat=$". /u/data/environment; onstat -g dri | grep -ie last -e type -e primary -e secondary -e ibm"
fred='/usr/bin/dzdo -u oseho /bin/ssh -qo PreferredAuthentications=publickey root@$infmx ". /u/data/environment; /usr/informix/bin/onstat -g dri | /usr/bin/grep -e on -e off | /usr/bin/grep -v informix | /usr/bin/grep -v data | /usr/bin/awk '{print $2}' | /usr/bin/cut -c1-2"'
if [ "$fred" == "on" ]; then
echo "DR is on, please resolve the ticket"
else
#Logs in to the informix box for the defined DC, then runs the above command
echo "Finding the status of DR on the primary and secondary Informix box:"
echo ""
echo "--------------------------------------------------------------------------------------------------------------"
echo ""
/usr/bin/dzdo -u oseho /bin/ssh -qo PreferredAuthentications=publickey root@$infmx $onstat
echo ""
echo "--------------------------------------------------------------------------------------------------------------"
fi