#!/bin/bash
echo "Export Tape(s):"
echo "---------------"
stdbuf -oL echo "list media" | bconsole | {
while IFS= read -r line
do
line=$(echo ${line^^})
if [[ "$line" == *"POOL"* ]] && [[ "$line" != *"DEFAULT"* ]] && [[ "$line" != *"FILE"* ]] && [[ "$line" != *"SCRATCH"* ]] && [[ "$line" != *"DUMMY"* ]]; then
echo " "
echo "$line" | awk '{print "["$2"]"}'
fi
if [[ "$line" == *"FULL"* ]]; then
inChanger=$(echo "$line" | awk '{print $20}')
if [[ "$inChanger" == 1 ]]; then
expiresIn=$(echo "$line" | awk '{print $31}')
if [[ "$expiresIn" != 0 ]]; then
echo "$line" | awk '{print " Date: "$28" Barcode: "$4}'
((tapesToExport++))
fi
else
newElement1=$(echo "$line" | awk '{print $4}')
if [[ $newElement1 != VOL* ]] && [[ $expiresIn = 0 ]]; then
newElement2=$(echo "$line" | awk '{print $28}')
tapeBarcode+=( $newElement1 )
tapeDate+=( $(date -d "$newElement2" +"%s") )
fi
fi
fi
done
IFS=$'\n' sorted=($(sort <<<"${tapeDate[*]}"))
unset IFS
sorted=( "${sorted[@]:0:$tapesToExport}" )
count=-1
for (( i=0; i<"${#tapeDate[@]}"; i++ )); do
(( count++ ))
if [[ "${sorted[$i]}" = "${tapeDate[$count]}" ]]; then
arrayOfRequiredIndexes[$i]=$count
else
(( i-- ))
fi
if [[ "$i" = "$((tapesToExport-1))" ]]; then
break
fi
done
if [[ "$tapesToExport" > 0 ]]; then
echo " "
echo -e "\e[1;37m╒═══════════════════════════════════════════════════════════════╕\e[0m"
echo -e "\e[1;37m│ Populate the TAPES.XLS file with the tapes above. │\e[0m"
echo -e "\e[1;37m│ Print EXCEL file and attach to each tape. │\e[0m"
echo -e "\e[1;37m│ │\e[0m"
echo -e "\e[1;37m│ Replace the "$tapesToExport" tape(s) that you'll export above │\e[0m"
echo -e "\e[1;37m│ with the "$tapesToExport" recommended below... │\e[0m"
echo -e "\e[1;37m╘═══════════════════════════════════════════════════════════════╛\e[0m"
echo " "
echo "Recommended Tapes to Import:"
echo "----------------------------"
for i in ${arrayOfRequiredIndexes[@]}; do
echo "Date: "$(date '+%Y-%m-%d' -d @${tapeDate[$i]})" Barcode: "${tapeBarcode[$i]}
done
else
echo " "
echo -e "\e[1;37mThere are no tapes to export.\e[0m"
echo " "
exit 1
fi
}
if [[ $? -eq 1 ]]; then
exit 0
fi
echo " "
echo "When you are finished importing the tape(s),"
echo "Type 'rescan' to issue a command for the tape"
echo "library to rescan. Or you can type 'exit' to"
echo "terminate the program."
while ! [[[ "${userResponse}" ];!= "exit" ]]; do
read -p "[rescan]/exit: " userResponse
if [[ "$userResponse" == "rescan" ]] || [[ -z "$userResponse" ]]; then
echo "update slots storage=TL2000-01 drive=0" | bconsole
exitfi
elsedone
echo " "
echo -e "\e[2;37mDone!\e[0m"
echo " "
exit
fi
done
#!/bin/bash
echo "Export Tape(s):"
echo "---------------"
stdbuf -oL echo "list media" | bconsole | {
while IFS= read -r line
do
line=$(echo ${line^^})
if [[ "$line" == *"POOL"* ]] && [[ "$line" != *"DEFAULT"* ]] && [[ "$line" != *"FILE"* ]] && [[ "$line" != *"SCRATCH"* ]] && [[ "$line" != *"DUMMY"* ]]; then
echo " "
echo "$line" | awk '{print "["$2"]"}'
fi
if [[ "$line" == *"FULL"* ]]; then
inChanger=$(echo "$line" | awk '{print $20}')
if [[ "$inChanger" == 1 ]]; then
expiresIn=$(echo "$line" | awk '{print $31}')
if [[ "$expiresIn" != 0 ]]; then
echo "$line" | awk '{print " Date: "$28" Barcode: "$4}'
((tapesToExport++))
fi
else
newElement1=$(echo "$line" | awk '{print $4}')
if [[ $newElement1 != VOL* ]] && [[ $expiresIn = 0 ]]; then
newElement2=$(echo "$line" | awk '{print $28}')
tapeBarcode+=( $newElement1 )
tapeDate+=( $(date -d "$newElement2" +"%s") )
fi
fi
fi
done
IFS=$'\n' sorted=($(sort <<<"${tapeDate[*]}"))
unset IFS
sorted=( "${sorted[@]:0:$tapesToExport}" )
count=-1
for (( i=0; i<"${#tapeDate[@]}"; i++ )); do
(( count++ ))
if [[ "${sorted[$i]}" = "${tapeDate[$count]}" ]]; then
arrayOfRequiredIndexes[$i]=$count
else
(( i-- ))
fi
if [[ "$i" = "$((tapesToExport-1))" ]]; then
break
fi
done
if [[ "$tapesToExport" > 0 ]]; then
echo " "
echo -e "\e[1;37m╒═══════════════════════════════════════════════════════════════╕\e[0m"
echo -e "\e[1;37m│ Populate the TAPES.XLS file with the tapes above. │\e[0m"
echo -e "\e[1;37m│ Print EXCEL file and attach to each tape. │\e[0m"
echo -e "\e[1;37m│ │\e[0m"
echo -e "\e[1;37m│ Replace the "$tapesToExport" tape(s) that you'll export above │\e[0m"
echo -e "\e[1;37m│ with the "$tapesToExport" recommended below... │\e[0m"
echo -e "\e[1;37m╘═══════════════════════════════════════════════════════════════╛\e[0m"
echo " "
echo "Recommended Tapes to Import:"
echo "----------------------------"
for i in ${arrayOfRequiredIndexes[@]}; do
echo "Date: "$(date '+%Y-%m-%d' -d @${tapeDate[$i]})" Barcode: "${tapeBarcode[$i]}
done
else
echo " "
echo -e "\e[1;37mThere are no tapes to export.\e[0m"
echo " "
exit 1
fi
}
if [[ $? -eq 1 ]]; then
exit 0
fi
echo " "
echo "When you are finished importing the tape(s),"
echo "Type 'rescan' to issue a command for the tape"
echo "library to rescan. Or you can type 'exit' to"
echo "terminate the program."
while ! [ "${userResponse}" ]; do
read -p "[rescan]/exit: " userResponse
if [[ "$userResponse" == "rescan" ]]; then
echo "update slots storage=TL2000-01 drive=0" | bconsole
exit
else
echo " "
echo -e "\e[2;37mDone!\e[0m"
echo " "
exit
fi
done
#!/bin/bash
echo "Export Tape(s):"
echo "---------------"
stdbuf -oL echo "list media" | bconsole | {
while IFS= read -r line
do
line=$(echo ${line^^})
if [[ "$line" == *"POOL"* ]] && [[ "$line" != *"DEFAULT"* ]] && [[ "$line" != *"FILE"* ]] && [[ "$line" != *"SCRATCH"* ]] && [[ "$line" != *"DUMMY"* ]]; then
echo " "
echo "$line" | awk '{print "["$2"]"}'
fi
if [[ "$line" == *"FULL"* ]]; then
inChanger=$(echo "$line" | awk '{print $20}')
if [[ "$inChanger" == 1 ]]; then
expiresIn=$(echo "$line" | awk '{print $31}')
if [[ "$expiresIn" != 0 ]]; then
echo "$line" | awk '{print " Date: "$28" Barcode: "$4}'
((tapesToExport++))
fi
else
newElement1=$(echo "$line" | awk '{print $4}')
if [[ $newElement1 != VOL* ]] && [[ $expiresIn = 0 ]]; then
newElement2=$(echo "$line" | awk '{print $28}')
tapeBarcode+=( $newElement1 )
tapeDate+=( $(date -d "$newElement2" +"%s") )
fi
fi
fi
done
IFS=$'\n' sorted=($(sort <<<"${tapeDate[*]}"))
unset IFS
sorted=( "${sorted[@]:0:$tapesToExport}" )
count=-1
for (( i=0; i<"${#tapeDate[@]}"; i++ )); do
(( count++ ))
if [[ "${sorted[$i]}" = "${tapeDate[$count]}" ]]; then
arrayOfRequiredIndexes[$i]=$count
else
(( i-- ))
fi
if [[ "$i" = "$((tapesToExport-1))" ]]; then
break
fi
done
if [[ "$tapesToExport" > 0 ]]; then
echo " "
echo -e "\e[1;37m╒═══════════════════════════════════════════════════════════════╕\e[0m"
echo -e "\e[1;37m│ Populate the TAPES.XLS file with the tapes above. │\e[0m"
echo -e "\e[1;37m│ Print EXCEL file and attach to each tape. │\e[0m"
echo -e "\e[1;37m│ │\e[0m"
echo -e "\e[1;37m│ Replace the "$tapesToExport" tape(s) that you'll export above │\e[0m"
echo -e "\e[1;37m│ with the "$tapesToExport" recommended below... │\e[0m"
echo -e "\e[1;37m╘═══════════════════════════════════════════════════════════════╛\e[0m"
echo " "
echo "Recommended Tapes to Import:"
echo "----------------------------"
for i in ${arrayOfRequiredIndexes[@]}; do
echo "Date: "$(date '+%Y-%m-%d' -d @${tapeDate[$i]})" Barcode: "${tapeBarcode[$i]}
done
else
echo " "
echo -e "\e[1;37mThere are no tapes to export.\e[0m"
echo " "
exit 1
fi
}
if [[ $? -eq 1 ]]; then
exit 0
fi
echo " "
echo "When you are finished importing the tape(s),"
echo "Type 'rescan' to issue a command for the tape"
echo "library to rescan. Or you can type 'exit' to"
echo "terminate the program."
while [[ "${userResponse}" != "exit" ]]; do
read -p "[rescan]/exit: " userResponse
if [[ "$userResponse" == "rescan" ]] || [[ -z "$userResponse" ]]; then
echo "update slots storage=TL2000-01 drive=0"
fi
done
echo " "
echo -e "\e[2;37mDone!\e[0m"
echo " "
The problem is that the very last readread statement isn't workingtaking input from the user. I've I will get prompted with "[rescan]/exit: " and I have the ability to type, but when I press it just asks for input yet again without the "[rescan]/exit: " prompt. There are no errors whatsoever. I have to CTRL-C out of the script to terminate it because it gets stuck (I'm assuming) on the last read statement. I've read all about how stdin is redirected and can't be leveraged by read until the program is complete, however I don't see anymy while loop is complete and none of the solutions on anyor fixes that actually workseem to circumvent my problem.
The problem is that the very last read statement isn't working. I've read all about how stdin is redirected and can't be leveraged by read until the program is complete, however I don't see any solutions on any fixes that actually work.
The problem is that the very last read statement isn't taking input from the user. I will get prompted with "[rescan]/exit: " and I have the ability to type, but when I press it just asks for input yet again without the "[rescan]/exit: " prompt. There are no errors whatsoever. I have to CTRL-C out of the script to terminate it because it gets stuck (I'm assuming) on the last read statement. I've read all about how stdin is redirected and can't be leveraged by read until the program is complete, however my while loop is complete and none of the solutions or fixes seem to circumvent my problem.
#!/bin/bash
echo "Export Tape(s):"
echo "---------------"
stdbuf -oL echo "list media" | bconsole | {
while IFS= read -r line
do
line=$(echo ${line^^})
if [[ "$line" == *"POOL"* ]] && [[ "$line" != *"DEFAULT"* ]] && [[ "$line" != *"FILE"* ]] && [[ "$line" != *"SCRATCH"* ]] && [[ "$line" != *"DUMMY"* ]]; then
echo " "
echo "$line" | awk '{print "["$2"]"}'
fi
if [[ "$line" == *"FULL"* ]]; then
inChanger=$(echo "$line" | awk '{print $20}')
if [[ "$inChanger" == 1 ]]; then
expiresIn=$(echo "$line" | awk '{print $31}')
if [[ "$expiresIn" != 0 ]]; then
echo "$line" | awk '{print " Date: "$28" Barcode: "$4}'
((tapesToExport++))
fi
else
newElement1=$(echo "$line" | awk '{print $4}')
if [[ $newElement1 != VOL* ]] && [[ $expiresIn = 0 ]]; then
newElement2=$(echo "$line" | awk '{print $28}')
tapeBarcode+=( $newElement1 )
tapeDate+=( $(date -d "$newElement2" +"%s") )
fi
fi
fi
done
IFS=$'\n' sorted=($(sort <<<"${tapeDate[*]}"))
unset IFS
sorted=( "${sorted[@]:0:$tapesToExport}" )
count=-1
for (( i=0; i<"${#tapeDate[@]}"; i++ )); do
(( count++ ))
line=$ if [[ "${sorted[$i]}" = "${tapeDate[$count]}" ]]; then
arrayOfRequiredIndexes[$i]=$count
else
(( i-- ))
fi
if [[ "$i" = "$((tapesToExport-1))" ]]; then
break
fi
done
if [[ "$tapesToExport" > 0 ]]; then
echo " "
echo -e "\e[1;37m╒═══════════════════════════════════════════════════════════════╕\e[0m"
echo -e "\e[1;37m│ Populate the TAPES.XLS file with the tapes above. │\e[0m"
echo -e "\e[1;37m│ Print EXCEL file and attach to each tape. │\e[0m"
echo -e "\e[1;37m│ │\e[0m"
echo -e "\e[1;37m│ Replace the "$tapesToExport" tape(s) that you'll export above │\e[0m"
echo -e "\e[1;37m│ with the "$tapesToExport" recommended below... │\e[0m"
echo -e "\e[1;37m╘═══════════════════════════════════════════════════════════════╛\e[0m"
echo " "
echo "Recommended Tapes to Import:"
echo "----------------------------"
for i in ${line^^arrayOfRequiredIndexes[@]}; do
echo "Date: "$(date '+%Y-%m-%d' -d @${tapeDate[$i]})" Barcode: "${tapeBarcode[$i]}
done
else
echo " "
echo -e "\e[1;37mThere are no tapes to export.\e[0m"
echo " "
exit 1
fi
}
if [[ $? -eq 1 ]]; then
exit 0
fi
echo " "
echo "When you are finished importing the tape(s),"
echo "Type 'rescan' to issue a command for the tape"
echo "library to rescan. Or you can type 'exit' to"
echo "terminate the program."
while ! [ "${userResponse}" ]; do
read -p "[rescan]/exit: " userResponse
if [[ "$userResponse" == "rescan" ]]; then
echo "update slots storage=TL2000-01 drive=0" | bconsole
exit
else
echo " "
echo -e "\e[2;37mDone!\e[0m"
echo " "
exit
fi
done
I've cut out a lot ofedited the code in order to just narrow down onpost and put all the problem I havecode so that there's full context. bconsole is a binary executable that I'm calling and the list media command does a dump of data to the stdout that I'm parsing with awk line-by-line.
stdbuf -oL echo "list media" | bconsole | {
while IFS= read -r line
do
line=$(echo ${line^^})
done
}
read -p "[rescan]/exit: " userResponse
I've cut out a lot of the code in order to just narrow down on the problem I have. bconsole is a binary executable that I'm calling and the list media command does a dump of data to the stdout that I'm parsing with awk line-by-line.
#!/bin/bash
echo "Export Tape(s):"
echo "---------------"
stdbuf -oL echo "list media" | bconsole | {
while IFS= read -r line
do
line=$(echo ${line^^})
if [[ "$line" == *"POOL"* ]] && [[ "$line" != *"DEFAULT"* ]] && [[ "$line" != *"FILE"* ]] && [[ "$line" != *"SCRATCH"* ]] && [[ "$line" != *"DUMMY"* ]]; then
echo " "
echo "$line" | awk '{print "["$2"]"}'
fi
if [[ "$line" == *"FULL"* ]]; then
inChanger=$(echo "$line" | awk '{print $20}')
if [[ "$inChanger" == 1 ]]; then
expiresIn=$(echo "$line" | awk '{print $31}')
if [[ "$expiresIn" != 0 ]]; then
echo "$line" | awk '{print " Date: "$28" Barcode: "$4}'
((tapesToExport++))
fi
else
newElement1=$(echo "$line" | awk '{print $4}')
if [[ $newElement1 != VOL* ]] && [[ $expiresIn = 0 ]]; then
newElement2=$(echo "$line" | awk '{print $28}')
tapeBarcode+=( $newElement1 )
tapeDate+=( $(date -d "$newElement2" +"%s") )
fi
fi
fi
done
IFS=$'\n' sorted=($(sort <<<"${tapeDate[*]}"))
unset IFS
sorted=( "${sorted[@]:0:$tapesToExport}" )
count=-1
for (( i=0; i<"${#tapeDate[@]}"; i++ )); do
(( count++ ))
if [[ "${sorted[$i]}" = "${tapeDate[$count]}" ]]; then
arrayOfRequiredIndexes[$i]=$count
else
(( i-- ))
fi
if [[ "$i" = "$((tapesToExport-1))" ]]; then
break
fi
done
if [[ "$tapesToExport" > 0 ]]; then
echo " "
echo -e "\e[1;37m╒═══════════════════════════════════════════════════════════════╕\e[0m"
echo -e "\e[1;37m│ Populate the TAPES.XLS file with the tapes above. │\e[0m"
echo -e "\e[1;37m│ Print EXCEL file and attach to each tape. │\e[0m"
echo -e "\e[1;37m│ │\e[0m"
echo -e "\e[1;37m│ Replace the "$tapesToExport" tape(s) that you'll export above │\e[0m"
echo -e "\e[1;37m│ with the "$tapesToExport" recommended below... │\e[0m"
echo -e "\e[1;37m╘═══════════════════════════════════════════════════════════════╛\e[0m"
echo " "
echo "Recommended Tapes to Import:"
echo "----------------------------"
for i in ${arrayOfRequiredIndexes[@]}; do
echo "Date: "$(date '+%Y-%m-%d' -d @${tapeDate[$i]})" Barcode: "${tapeBarcode[$i]}
done
else
echo " "
echo -e "\e[1;37mThere are no tapes to export.\e[0m"
echo " "
exit 1
fi
}
if [[ $? -eq 1 ]]; then
exit 0
fi
echo " "
echo "When you are finished importing the tape(s),"
echo "Type 'rescan' to issue a command for the tape"
echo "library to rescan. Or you can type 'exit' to"
echo "terminate the program."
while ! [ "${userResponse}" ]; do
read -p "[rescan]/exit: " userResponse
if [[ "$userResponse" == "rescan" ]]; then
echo "update slots storage=TL2000-01 drive=0" | bconsole
exit
else
echo " "
echo -e "\e[2;37mDone!\e[0m"
echo " "
exit
fi
done
I've edited the post and put all the code so that there's full context. bconsole is a binary executable that I'm calling and the list media command does a dump of data to the stdout that I'm parsing with awk line-by-line.