bash: How to prompt for user input while reading file?
0
votes
1
answer
117
views
Following script statement for user input is nested in while loop under if block but it doesn't work and is being skipped. How do I get user input to work?
3<&0 && read -p 'Enter your answer: ' uservar <&3
FILE="hostnames.txt"
echo $(sudo chmod +777 $FILE)
echo "Step 1. Checking if file with hostnames exists."
#exec 3<&0
if [ -f "$FILE" ]
then
echo "PASSED: File hostnames.txt does exist." && echo ""
while IFS= read -r hostname;
do
echo "Step 2. Checking Grph mgmt_con_ip4 exists for $hostname"
mgmt_con_ip4="$(echo "$(llama-grph node show $hostname | grep mgmt_con_i$
echo "Grph has management IPv4 address: $mgmt_con_ip4"
if [ -z $mgmt_con_ip4 ]
then
echo "PASSED: Grph mgmt_con_ip4 == NULL" && echo ""
else
echo "FAILED: Grph mgmt_con_ip4 == NOT NULL" && echo ""
echo "$(ipam --format json get-cidr-parent $mgmt_con_ip4)" && echo ""
echo "WARNING: OOB networks shouldn't have $mgmt_con_ip4 IPv4 addres$
exec 3<&0 && read -p 'Enter your answer: ' uservar <&3
fi
done < $FILE
fi
Asked by Python_new
(9 rep)
Mar 30, 2023, 11:27 PM
Last activity: Feb 15, 2024, 11:03 PM
Last activity: Feb 15, 2024, 11:03 PM