Category Archives: Linux Tricks

How to Check if Apache Is Up and Restart if Not

I do often monitor server apache status as most often reason of server outages is Apache overload. Some web hosting panels are sending notifications when your server is down; some web services like provide you with different notification options and one of my hosters has his internal monitoring service. But what to do if you need to… Read More »

Running a Cron Job Once a Day at a Random Time

Let’s say we need to randomize the time to run a cronjob. We need to run a script once a day but the time should be different each day. How should we proceed? I’ve got some solutions for this. The first one is a little stupid, but it will work if you have your own dedicated server. If… Read More »

How To Select All Files in A Midnight Commander Panel

Today my post will be quite short: a simple yet useful keyboard shortcut for mc. Often you need to select all files in a Midnight Commander panel, just like using Ctrl+A in Windows. Mignight commander has another shortcut, that uses mask and allows you to select all the files in a mc panel. Here is your initial view:… Read More »

How to Change Owner for All Files in a Folder Linux

A system administrator often needs to deal with file ownership change. This is often related to the ownership of the files created by daemons. Often users don’t have access to the file created by apache. What to do if you need to change ownership of a group of files? You must be root to perform this operation. The… Read More »

How to Block Outgoing Connections using iptables

Sometimes you should prevent outgoing connections from your server. The best way to do it is to use Linux system options, especially ipchains and iptables. I will show you how to do it using iptables, as this is the shortest way I know. In order to block outgoing connections from your server to one IP issue the following… Read More »

How to Change Owner of Files Created by Apache

If you manage any script that creates files on the server, you might meet the prob;em that you cannot edit files created by this script. This is especially related to PHP scripts, that, for example, create some text files in a folder. When you try to open these files via your FTP client, you will most probably receive… Read More »

How to Deny Responses to Ping Requests Using iptables

Sometimes you need to “hide” your server by denying responses to ping requests. This way your server will look like it is offline. ping <server_ip> will return connection timeout. There is a short linux command that will allow to do this using iptables. Here it is: iptables -t filter -A INPUT -p icmp -j REJECT This will ignore… Read More »