@vgaetera suggest ( and I think so) that pinging the default GW (something near your, but of course, outside of home/biz devices you manage) is a better option...
@trendy maybe ping 8.8.8.8 is a guarantee* like www.cisco.com ping 2 decades ago, but why do you suggest this one?
*guarantee because this service are offered with high-available, load balancing setup so you never get a false positive response (rebooting your router without connection loss)
Unlike your ISP gateway which usually supports ICMP traffic, hosts on the Internet are not obligated to reply to your pings and some internet services explicitly block ICMP traffic.
Moreover, there's typically no point to restart the router when the Internet connectivity fails, but the ISP connectivity is fine.
The only valid reason to rely on higher level connectivity is a dynamic ISP gateway which might require scripting to keep up-to-date.