OpenSUSE Linux Rants

OpenSUSE Linux Tips, tricks, how-tos, opinions, and news

My Resume  -  My LinkedIn Profile

October 8, 2007

Linux caught sleeping on the job

by @ 6:51 am. Filed under command-line, General Linux, Linux tips

Linux has to be one of the coolest things ever. Its versatility is literally dizzying. It runs Meter Maids, is used onboard the Space Shuttle, and can control the military’s autonomous vehicles.

Of the scores and scores of cool commands, utilities, and features of the Linux operating system, I wanted to take a look at two of perhaps the smallest. Even these have proven very useful in recent days.

The first is the semicolon. This bad boy can be used on the commandline to separate commands that you want to run in sequence. For example, if you wanted to list the contents of the current folder and also view information about your computer’s cpu, you could do this:

ls ; cat /proc/cpuinfo

Why you would ever want to do exactly that series of commands is beyond me, but it’s an example. 🙂

The second item of business is the ‘sleep’ command. This simply makes the OS pause for a number of seconds.

If you wanted to view the contents of the current directory, then pause for 5 seconds, and then view your cpu info:

ls ; sleep 5 ; cat /proc/cpuinfo

OK, time for a real-world application.

Let’s say you have a remote machine whose mail server is choking the connection, making it difficult if not impossible to connect to said system. It is sending out hundreds of huge emails. The bandwidth is being used up, and you cannot connect in to fix the issue. With the assistance of someone who is able to physically sit at the computer, you are able to shut down the mail server, allowing you to connect in remotely.

Now, you are ssh’ed into the affected box. You want to test the mail server to see what is going on. However, you know that as soon as you start up postfix, you will again be unable to connect to the machine. So what do you do?

This was the situation that I was in a couple of days ago. In this instance, I opened up another ssh window and connected into the system. I then ran a series of commands, separated by semicolons, and using ‘sleep’. The idea is that I want the machine to start postfix, run it for 30 seconds, and then shut it back down. This gave me just a few seconds to monitor what was happening before my connection got choked out again. After the 30 seconds, the final command shut down postfix. I was then be able to get back in via ssh.

Here’s the command line I used:

/etc/init.d/postfix start ; sleep 30 ; /etc/init.d/postfix stop

Linux provides a myriad of ways to do whatever task is at hand. Because of this versatility, we can use the semicolon and utilities like ‘sleep’ to help in cases like the one described above.

One Response to “Linux caught sleeping on the job”

  1. Tom Goren Says:

    just fyi in this case, you could have forgone opening another ssh window, by ending the command with an & (ampersand), thus sending your command to the background.
    or by using screen, an all useful tool, which i am sure you are familiar with.

OpenSUSE Linux Rants
Official OpenSUSE Linux Site

internal links:


SUSE Resources

search blog:


March 2022
« Feb    

59 queries. 0.229 seconds