🧡 Skip to main content🔍 Skip to search
Matthew AdamsBy Matthew Adams 🕓 Published on January 22, 2021 at 4:00 pm
YouTube video · Ping server regularly

A tutorial on how to create a Task in the Automation Workshop app that executes the ping command to a server every 30 seconds, and when the server is not reachable, it sends email automatically.

The email body contains output of the ping command, and optionally output of the tracert command (traceroute). The task uses a built-in Advanced Task Scheduler and the task execution interval can be easily changed from 30 seconds to any schedule, including options for including and excluding specific times, days, weekdays, etc.

This tutorial also demonstrates how to capture the output of CMD window and send it as an email message. The task can be extended with more than 100+ automated Actions, starting from an alarm sound, and ending with document printing, or operations on remote FTP servers.

Get the Demo Task…

Note

The video tutorial and task example above is using the latest features of Automation Workshop, and it is a recommended approach of creating branching in tasks using If Action. Please download it and import into Automation Workshop to start monitoring your server in just a few minutes. However, the text version below is using On Error feature to differentiate a success and failure of the ping command.

Overview

Suppose that you have two servers, and you want to make sure that a connection between servers is always available. We will use the Windows built-in ping command to ping a server every 30 seconds. If the connection goes offline, or the server is not responding to the ping command, we will send an email with output of the ping and tracert (traceroute).

Solution

Use a built-in Advanced Task Scheduler to periodically launch an Action, in this case the Execute Script Action, which is configured to ping the server and send an email to the specified address when not receiving a server reply.

How to ping a server?

How to periodically ping an IP address of the server? The creation of a Task can be divided in three simple parts. First, a new Task has to be created. Second, you will need to add and configure the Task Scheduler Trigger, the function of which is to periodically execute the Task. Third, you will need to set up the Action that will ping the server whenever the Task is triggered by Task Scheduler.

How to create a Task?

Creating a new Task in Automation Workshop is very easy. Open the Automation Workshop Manager by clicking on the Febooti Automation Workshop program icon in the Start menu. Then create a new Task by clicking on the New task button. The Task Wizard will be opened to provide step-by-step assistance.

Add an Advanced Task Scheduler

How to add the Task Scheduler trigger to the Task? Follow these simple steps:

  • Go to the Triggers tab (after the Welcome screen). Start adding Triggers to the Task.
  • Click the Add… button and a list of available Triggers will be opened.
  • Choose the Task Scheduler trigger and click OK. See the Task Scheduler properties.

Configure the Task Scheduler

How to configure the Advanced Task Scheduler trigger to periodically start the Task? Let us suppose that for our goals it is sufficient to ping the server once per every 30 seconds. As you can see, by default Task Scheduler offers to create a Task which is scheduled daily at the same time. What we need is to change schedule type from daily to seconds. Set an appropriate Start date and configure Task Scheduler to Recur every 30 seconds.

Task Scheduler: recur every 30 seconds
Recur every 30 seconds

If you want to prevent the task from launching on a particular time, days of the week, dates, or months, use the Task Scheduler exceptions to exclude these periods. Click OK and you will see the Task Scheduler trigger appear in the Trigger list of Task Wizard. Click Next to proceed with setting up Actions.

Add an Action

How to add an Action to ping the server periodically? An Action is added in the same way as Trigger, just click the Add… button when in the Action tab of Task Wizard. Automation Workshop does not feature a built-in ping command, however it is very efficient for running external commands. In this case, we will use an Action that can run command line applications. Open Run category, select Run CMD Command Action and click OK. Starting from the v2.0 of Automation Workshop, it is recommended to use Execute Script Action as shown in the demo task and video tutorial above.

Ping the server

How to configure an Action to ping the server periodically? We need to tell Run CMD Command Action to run the PING command to ping the particular IP address.

For the sake of example, let us suppose that the server's IP address is 192.168.1.101. Write the ping -n 1 192.168.1.101 into a Command line input (on Command tab of Run CMD Command Action).

Ping server from command line: ping -n1 192.168.1.101
ping -n1 192.168.1.101

The -n 1 parameter means that only one data packet will be sent per time to ensure server connectivity. If connection is somewhat unstable, you might want to increase the number of data packets sent each time. Note that you will have to substitute 192.168.1.101 with the actual server IP address (or DNS name if available).

Detect failed pings

How to detect failed ping requests and automatically send error reports? So far the Task is set to ping the server every 30 seconds. However, we also need to set up error reporting which will occur whenever the server fails to respond to the ping request.

When the ping command manages to get through and receives server reply, its errorlevel is set to 0 (which means successful completion). If not, the errorlevel will differ from 0.

We strongly recommend to not use the errorlevel anymore. It is not reliable for the ping command. Instead use the TTL parameter from the output of the ping command. See the demo task that is included in this article, or view the video tutorial above.

CMD command: Treat error levels greater than 0 as error
Treat error levels greater than 0 as error

Run CMD Command Action can process returned errorlevels. In this case, we will need to set the option to Treat error levels greater than 0 as error. Which means that anything but completely successful ping will be treated as error. Note that Wait for command to complete or terminate must be selected in order for Run CMD Command to wait for the results of ping command before finishing the Task.

Email reports

How to send an email with an error report when the Action experiences an error? After setting up periodical pinging and treating non-zero (non-success) errorlevels as errors, we need to tell Action what actually to do when experiencing an error.

Switch to the On Error tab of Run CMD Command properties, check the Send email when this Action encounters an error checkbox and provide the email address of sender (From field) and recipient (To field) that will be used when sending error notification email.

Send email when ping encounters an error
Send email upon ping error

Click OK and the Action will be saved. Essentially, the Task is ready. You might want to check other options for additional configuration, if necessary, but normally the Task will become active as soon as created (and begin pinging starting from the date and time specified in the Task Scheduler settings).

Note that during the server downtime, an email will be generated every 30 seconds which can lead to a large amount of sent emails during somewhat longer downtime. Also, in order to maintain the comprehensiveness of the log file when running frequently recurring Tasks, you might consider choosing Log only Task errors and warnings in the Log tab of Task Properties.

Conclusion

This tutorial is an example, how to use the Advanced Fallback Settings to split a task execution flow into two branches. It was a recommended way before Automation Workshop v2.0, when the If Action was not available. From now on, it is recommended to use the If Action, as shown in the demo task and video at the beginning of this tutorial.

The Task described in this tutorial might be insufficient to diagnose a connectivity problem. For more comprehensive approach, you might want to:

  • Perform tracert command (traceroute) to server and gateway & router.
  • Ping DNS to check whether it is working properly.
  • Save the information returned by tracert and ping commands into report.txt file for later reviewing. Depending on the situation, executing a media player that plays an audible alarm can also prove really useful.

Seamless automation in action! 90 seconds to efficiency.

Help at your fingertips…

If you have any questions, please do not hesitate to contact our support team.