# Run ping command every hour in backgrond

**URL:** <https://community.unix.com/t/run-ping-command-every-hour-in-backgrond/366543>\
**Category:** Shell Programming and Scripting\
**Created:** [May 12, 2017, 2:28pm UTC](https://community.unix.com/t/run-ping-command-every-hour-in-backgrond/366543 "2017-05-12T14:28:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![solaris\_1977](https://community.unix.com/letter_avatar/solaris_1977/32/6_449c533f586939b6e5f246632a46421f.png) [@solaris\_1977](https://community.unix.com/u/solaris_1977)\
**Post date:** [May 12, 2017, 2:28pm UTC](https://community.unix.com/t/run-ping-command-every-hour-in-backgrond/366543/1 "2017-05-12T14:28:05Z")

</div>

Hi,  
I have a VPN tunnel. It is going down occasionally. I need to run "/usr/sbin/ping 172.xx.xx.xx.xx" and it give mes output "172.xx.xx.xx is alive" and immediately after that VPN tunnel comes up.  
Till we find permanent solution, I want this command to run in background, like every one hour. Should I simply have below entry in cronjob ?

```nohighlight
0 * * * * /usr/sbin/ping 172.xx.xx.xx.xx

```

Or any other way ?

---

<div class="post-metadata">

**Author:** ![RudiC](https://community.unix.com/letter_avatar/rudic/32/6_449c533f586939b6e5f246632a46421f.png) [@RudiC](https://community.unix.com/u/RudiC)\
**Post date:** [May 12, 2017, 3:25pm UTC](https://community.unix.com/t/run-ping-command-every-hour-in-backgrond/366543/2 "2017-05-12T15:25:25Z")

</div>

I don't see an immediate problem except the strange IP format. What's the result if you install that crontab entry?

---

<div class="post-metadata">

**Author:** ![solaris\_1977](https://community.unix.com/letter_avatar/solaris_1977/32/6_449c533f586939b6e5f246632a46421f.png) [@solaris\_1977](https://community.unix.com/u/solaris_1977)\
**Post date:** [May 12, 2017, 4:32pm UTC](https://community.unix.com/t/run-ping-command-every-hour-in-backgrond/366543/3 "2017-05-12T16:32:56Z")

</div>

It is not executing via crontab. I am root. ( I am giving actual IP, not xx.xx.). Just for testing purpose, I made it every minute

```nohighlight
bash-3.2# crontab -l | grep -i ping
* * * * * /usr/sbin/ping 172.23.xx.xx > /tmp/ping_test
bash-3.2# cat /tmp/ping_test
cat: cannot open /tmp/ping_test
bash-3.2#

```

If I run command manually, I can see output in /tmp/ping\_test

---

<div class="post-metadata">

**Author:** ![RudiC](https://community.unix.com/letter_avatar/rudic/32/6_449c533f586939b6e5f246632a46421f.png) [@RudiC](https://community.unix.com/u/RudiC)\
**Post date:** [May 12, 2017, 5:21pm UTC](https://community.unix.com/t/run-ping-command-every-hour-in-backgrond/366543/4 "2017-05-12T17:21:45Z")

</div>

Can't tell why it behaves as described. Is the path correct?  
If I reproduce your setup, `cron` creates an (endlessly) `ping` ing process every minute. You might want to limit the `ping` count so it stops after a few pings.  
`/tmp/ping_test` is `cat` able all the time. That error message I can't reproduce; all I get is `cat: /tmp/pt: No such file or directory` in case.

---

<div class="post-metadata">

**Author:** ![solaris\_1977](https://community.unix.com/letter_avatar/solaris_1977/32/6_449c533f586939b6e5f246632a46421f.png) [@solaris\_1977](https://community.unix.com/u/solaris_1977)\
**Post date:** [May 12, 2017, 5:53pm UTC](https://community.unix.com/t/run-ping-command-every-hour-in-backgrond/366543/5 "2017-05-12T17:53:00Z")

</div>

Yes, path is correct. If I run it manually, it works

```nohighlight
bash-3.2# crontab -l | grep -i ping
* * * * * /usr/sbin/ping 172.23.xx.xx > /tmp/ping_test
bash-3.2# which ping
/usr/sbin/ping
bash-3.2# cat /tmp/ping_test
bash-3.2# /usr/sbin/ping 172.23.xx.xx > /tmp/ping_test
bash-3.2# cat /tmp/ping_test
172.23.xx.xx is alive
bash-3.2#

```
