Bash: Run command after another

What many of you probably know is that you can chain commands together with the semicolon. Like so:

So here we’re running a unixbench, and then directly after, we’re appending “unixbench finished” to unixbench.log.

But what you might not know about is the ‘&&’ replacement for ‘;’. This will only do the next command if the first command returns 0, meaning clean finish.

And taking it a step further, there’s ‘||’ which does the opposite of ‘&&’. If the first command fails, then the next command happens.


Ubuntu 12.04 x86_64 Poor Performance on Hyper-V in Windows 8

As of the Hyper-V Version: 6.2.9200.16384, Ubuntu 12.04 x86_64 performs very slow as a guest os. I switched to CentOS 6.2 x86_64 and performance was dramatically increased. It should be noted that “Linux Integration Services Version 3.4 for Hyper-V” was installed on the CentOS system, but not the Ubuntu system. I’ll investigate this at a later date.

I’ll post a unixbench of both VMs when I get a maintenance window. But for now, examine these load averages. Both running a minecraft server (Bukkit 1.4.6-R0.1) of the same world with the same amount of people. Both had 4GB of ram and 4 CPUs.

Ubuntu 12.04 x86_64: load average: 2.65, 2.92, 2.47

CentOS 6.2 x86_64: load average: 0.14, 0.11, 0.09


EDIT 12/27/2012

UnixBench Ubuntu 12.04

UnixBench CentOS 6.2

rc.local and sudo on CentOS

If you have a sudo command you’re trying to run at startup in your /etc/rc.local on a CentOS system, it might not work. The reason is the following error that’s buried in the /var/log/boot.log file:

It might be hard to find, but you can always add a ‘sleep 30’ before your sudo command in your /etc/rc.local. This way, the message will show up at the end of the boot.log

Anyhow the reason this is happening is for security. To allow sudo on boot, run ‘visudo’ as root and comment out ‘Defaults requiretty’ as seen below:

Now your sudo command should run just fine at boot time.


Here’s an example of why you might want to run sudo at boot.

In the above command, I’m running the script startMinecraft, as the user minesrv. startMinecraft has some screen magic, and I want it tied to the minesrv user.

Startup script for GNU screen

Here’s how you start up a GNU screen session at startup and give it a command to run.

So in this case we’re starting a minecraft server in a screen session.

Per the man page -dm does the following:

the -S gives the screen session a name so it’s easier to find later on.

Then it runs the command, java, with its parameters.


Another useful tool is sudo, so we can run our above startup script as a different user than root.

startMinecraft is the first bash script above. Here we’re using sudo to run it as the user ‘minesrv’.

The -i makes sudo perform all the standard login processes before running the script.


And finally, you can just reference the startup script inside /etc/rc.local for most linux distros. That will make the script run at startup.