#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
?
내가 뭘 잘못했나요?