我有一个问题,而且我对编写 bash 还是很陌生。我正在解析一个 csv 文件,检查一些东西。如果检查为真,则更改稍后将写入文件的变量。我正在读取输入文件并输出到文件,如果某个参数检查为 True,那么我想提示用户并暂停脚本,直到用户验证信息匹配(手动验证)。
我最近的尝试没有提示。它只是继续读取和写入输出。我很确定,因为输出将直接转到我的输出文件,但我不知道如何将提示引导到我被卡住的终端窗口。
INPUT=$TMPSAVE
IFS=,
[ ! -f $INPUT ] && { echo "$INPUT file not found"; exit 99; }
while read cdwon cdwod manu_date hp_sn manu_sn wiped_by wiped_date checked_by disposition readonly
do
for i in ${!allassigned[@]}
do
if [[ -n $manu_sn ]]
then
if echo ${allassigned[i]} | grep -q $manu_sn
then
physicaldrive=${allassigned[i-1]}
disk=$(hpacucli ctrl slot=${SLOT} show config detail | grep -B 4 ${physicaldrive} | head -1 | awk '{print $NF}');
if [[ -n $disk ]]; then #proceed to wipe drive
mount ${disk}${PRIMARY} ${MOUNT}
if [ -e $DIR ]; then
####### the file exists, now what to do with it? Automatcially prompt user?
cat $DIR > /dev/tty
echo "Does the drive serial number (${allassigned[i]}) match what was provided from the database ($manu_sn)? (y/n)" > /dev/tty
read
if [ "$REPLY" == "Y" ] || [ "$REPLY" == "y" ] || [ "$REPLY" == "YES" ] || [ "$REPLY" == "yes" ]; then
checked_by=$username
checked_bydate=`date`
fi
fi
fi
fi
fi
done
echo "$cdwon,$cdwod,$manu_date,$hp_sn,$manu_sn,$wiped_by,$wiped_date,$checked_by,$disposition,$readonly";
continue;
done < $INPUT > $OUTPUT