#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'
また、2番目のelseはどこに置くことができますかif
?
私は何が間違っていましたか?