A bash script to test a service established or not.

Need help with C, C++, perl, python, etc?

A bash script to test a service established or not.

Postby hack3rcon » 2020-03-22 20:04

Hello,
I want to write a bash script to restart a service and if the service launched successfully and established then execute the next command.
For example, restart the Apache service and when the service established then the next command execute.

Thank you.
hack3rcon
 
Posts: 386
Joined: 2015-02-16 09:54

Re: A bash script to test a service established or not.

Postby arzgi » 2020-03-23 13:58

Code: Select all
#!/bin/bash

[start Apache] && [next]




&& operator starts the second only if the first was succesfull
arzgi
 
Posts: 638
Joined: 2008-02-21 17:03
Location: Finland

Re: A bash script to test a service established or not.

Postby zero00 » 2020-05-12 13:36

Hi,

This can help you..

Code: Select all
#!/bin/bash

systemctl restart apache2

if [ $? = '0'  ]; then
        < next command >
fi
zero00
 
Posts: 1
Joined: 2020-05-12 13:30


Return to Programming

Who is online

Users browsing this forum: No registered users and 2 guests

fashionable