# Auto ping and dhcpcd?

## audiodef

I have an old HP Proliant which I run headless. If I accidentally turn off my router before shutting it down via ssh, I would have to force it off, which generates a fault code that would require me to attach a keyboard and monitor - which would be a PITA. 

What would be the best way to write either an init script or a cron/bash script to run ping every so often, and if ping fails (at which point the assumption is I've accidentally shut off my router), to restart dhcpcd (at some point, I will turn my router back on, so the connection will be reestablished)?

----------

## MacGyver031

If you have a newer dhcpcd, there are hooks 

```
/lib/dhcpcd/dhcpcd-hooks
```

 which contain the handling of dhcp-lease and so on. 

But AFAIK, the server will request ip-address once it has connection and when the timeout has occured. If the machine is connected to the router directly, the request for a new ip should occur immediately as the router is switched on again.[/code]

----------

## audiodef

I assign a local network address manually, but if it reconnects automatically, that's even better. I'm sure I'll verify that at some point when I turn the router off before I issue halt on the server...

----------

