Restart Apache if failed

This bash script check web site every 5 minutes, restart the web server if web site is not responding. Create a file

Add

In above code, replace https://YOUR_DOMAIN.EXTN/ with your sites actual url. Make it executable

Create a cronjob

Add

See Server Monitoring […]

Read More…

Bash check if a program is running or not

You can find process id for a running program with command

Example

We can use pidof command in bash script to find if a program is running or not

See bash […]

Read More…

bash check if a folder is empty or not

To check if a folder is empty of not, you can use

If you want to reverse the checking, you can use !

See bash […]

Read More…

Bash check if a directory exists

To check if a directory exists in bash, use

To check for absense of a directory, use !

See bash […]

Read More…

Bash if statement

Check if first augment to script is –help

Check if a file exists and is executable

Check if a binary file exists and is executable

Check if previous command was sucessfull or not

Check if variabe set or not

[…]

Read More…

bash

Bash shortcuts

Enable color prompt Edit .bashrc, add following

Logging Linux Commands for all users Bash if statement Bash Script to Monitor Disk Usage Bash check if a directory exists Auto Restart MySQL if Crashed bash check if a folder is empty or not Bash check if a program is running or not […]

Read More…