I am trying to create a nested case statement in which user input is expected (Y/N). However, the system never waits for the input and always goes to the third option, "Please answer yes or no". Can anyone tell me what I am missing?
Here is the case statement
#!/bin/bash
SERVSTAT=/mnt/support/scripts/log/serverstatus.txt
FUSE_PATH=/home/jet/instances/
LOG=data/log/karaf.log
echo " " > $SERVSTAT
STATUS=status
find /etc/init.d/* -name '*service' -print0 | while IFS= read -r -d '' FILE;
do
if [ "$FILE" != "." -o "$FILE" != ".." ]; then
APP_NAME=`echo ${FILE:12} | sed 's/-service//'`
OUTPUT=$($FILE $STATUS)
case "$OUTPUT" in
*not* )
echo "Do you wish to start $APP_NAME ?"
read yn
case $yn in
[yY] | [yY][Ee][Ss] )
$FILE start
tail -f $FUSE_PATH/$APP_NAME/$LOG
;;
[nN] | [n|N][O|o] )
;;
* )
echo "Please answer yes or no.";;
esac
;;
* )
echo "App $APP_NAME is running"
esac
fi
done
I'm Trying to execute this in RHEL 6
-p
flag toread
takes an argument, which is swallowing your variable name. Tryread -p foo yn
. – MadHatter Jun 26 '14 at 07:34