![Bash의 시간 비교가 작동하지 않고 구문 오류가 발생합니다.](https://linux55.com/image/191538/Bash%EC%9D%98%20%EC%8B%9C%EA%B0%84%20%EB%B9%84%EA%B5%90%EA%B0%80%20%EC%9E%91%EB%8F%99%ED%95%98%EC%A7%80%20%EC%95%8A%EA%B3%A0%20%EA%B5%AC%EB%AC%B8%20%EC%98%A4%EB%A5%98%EA%B0%80%20%EB%B0%9C%EC%83%9D%ED%95%A9%EB%8B%88%EB%8B%A4..png)
#Run if time is between these two times
hour_first="19:59"
hour_last="22:01"
array_hosts=( "192.168.2.254;VPN one" "192.168.21.3;another vpn name" )
last_reset=""
reset_vpns(){
current_time=$(date +%H:%M) # format : HH:MM with lead 0 if less than 10
current_day=$(date +%j)
echo $current_time
echo $current_day
if ! [[ "$current_day" -eq "$last_reset" ]]; then
# if the current time is between the allow timeframe for resets
if [[ "$current_time" > "$hour_first" ]] && [[ "$hour_last" > "$current_time" ]];then
for element in "${array_hosts[@]}";do
vpnname=$(echo "$element" | awk -F";" '{print $2}')
echo "Daily Reset VPN: $vpnname "
/usr/local/bin/php /usr/local/bin/pfsense-vpnreset.php "$vpnname"
done
echo $current_day > $log_file
fi
fi
}
reset_vpns
위의 코드는 VPN을 매일 재설정해야 하는지 확인합니다.
그러나 실행하면 해당 줄에 다음 구문 오류가 발생합니다.
if [[ "$current_time" > "$hour_first" ]] && [[ "$hour_last" > "$current_time" ]];then
실수:
main.sh: line 14: conditional binary operator expected
main.sh: line 14: syntax error near `"$hour_first"'
main.sh: line 14: ` if [[ "$current_time" "$hour_first" ]] [[ "$hour_last" "$current_time" ]];then'
또한 두 번째 else 는 어디에 둘 수 있나요 if
?
내가 뭘 잘못했나요?