What’s the best way to check if a volume is mounted in a Bash script?

What’s the best way to check if a volume is mounted in a Bash script? What I’d really like is a method that I can use like this: if <something is mounted at /mnt/foo> then <Do some

Source: What’s the best way to check if a volume is mounted in a Bash script?

Avoid using /etc/mtab because it may be inconsistent.

Avoid piping mount because it needn’t be that complicated.


if grep -qs '/mnt/foo' /proc/mounts; then
    echo "It's mounted."
    echo "It's not mounted."

Ikea Patched for Shellshock by Methodically Upgrading All Servers

Glantz explained that the first step in the assembly of his IT infrastructure is to have a well-defined Standard Operating Environment (SOE). The SOE includes a definition of the hardware platforms used as well as the Linux and application software that is installed. There is also an installation and configuration management layer that helps enforce the SOE across the distributed Ikea IT footprint. Additionally, Glantz has defined a lifecycle-management plan that describes the lifecycle of how Linux will be used at Ikea for the next seven years.”

It’s not enough just to have documents, you have to have systems driving how technology works,” Glantz said.

Source: Ikea Patched for Shellshock by Methodically Upgrading All Servers

Mars Rover’s ChemCam Instrument gets sharper vision

Likewise, the laser analyses were done at nine different focus settings to obtain one good set of data. In the meantime, the team went back to the drawing board. They figured out that if they discarded a lot of the old code on board their distant subject, they could make room for software that could command the instrument to take the nine images on its own and analyze them on-board to find the best focus.

Source: Mars Rover’s ChemCam Instrument gets sharper vision

The program to run the whole instrument is only 40 kilobytes. The first tests on Mars were completed earlier this week.

This Robot Is the Best Limit Texas Hold’Em Player in the World

Poker being what it is, the robot, named Cepheus after a constellation in the northern hemisphere, will lose if it’s dealt an inferior hand, but it will minimize its losses as best as is mathematically possible and will slowly but surely take your money by making the “perfect” decision in any given scenario. Heads-up limit Hold’Em, it can be said, has been “solved.”

via This Robot Is the Best Limit Texas Hold’Em Player in the World | Motherboard.

And it was solved by computer scientists at the University of Alberta who don’t actually play the game. That’s because solving the game is more of a math problem than anything else.

This development is like when they discovered Basic Strategy for blackjack.

Sendmail Problems

You can use the mailq command sendmail -bp command to display a summary of the mail messages queued for future delivery. Type the following command:
# mailq

via Sendmail: Clear / Delete / Flush Mail Queue.

A service in a local server started to send email through my main server back to the originating server causing many errors in /var/log/maillog of my main server.  Each attempt added a message to its message queue that was blocked due to a problem with sendmail on the originating server.  The email being sent was sent automatically by a VOIP service I was testing on that originating server (not good).

You can cd to /var/spool/mqueue and delete all files if you want to get rid of all messages in the queue:
# cd /var/spool/mqueue/
# ls
# rm *

The above sequence cleared the queue so sendmail stopped trying to send those messages to a broken server at the destination.

Sendmail Problem on Originating Server

Sendmail wouldn’t start.  OS Fedora 19 so it’s running that new systemd for service startup.   Here are pertinent error messages in  /var/log/messages:

Nov 17 21:23:39 ana systemd[1]: Starting Sendmail Mail Transport Agent...
Nov 17 21:23:39 ana sendmail[1555]: -bd is not supported by sSMTP
Nov 17 21:23:39 ana systemd[1]: PID file /run/sendmail.pid not readable (yet?) after start.
Nov 17 21:23:39 ana systemd[1]: Failed to start Sendmail Mail Transport Agent.
Nov 17 21:23:39 ana systemd[1]: Dependency failed for Sendmail Mail Transport Client.
Nov 17 21:23:39 ana systemd[1]: Unit sendmail.service entered failed state.

I did a lot of googling to find someone in a similar situation to no avail.  I then looked into sSMTP and why that was being called  instead of good old sendmail.  After

#yum erase sSMTP

thus purging that service entirely from the system,  sendmail starts in this Fedora 19 VM and works (knock on wood).

Calculating distance between longitude and latitude pairs

Problem: I need a simple way to calculate distance between two pairs of longitude and latitude coordinates.

Apparently there are several ways of making this calculation.  Since none of my calculations would exceed 15 miles I was able to use the flat earth calculation which is the simplest but inaccurate as distances increase between the two points according to this wikipedia article.  Here’s a blurb about the flat-earth formula:

Flat-surface formula

A planar approximation for the surface of the earth may be useful over small distances. The accuracy of distance calculations using this approximation become increasingly inaccurate as:

  • The separation between the points becomes greater;
  • A point becomes closer to a geographic pole.

There were a bunch of sites that came up with all the different formulae over this but I’m not launching a satellite or programming a guided missile. The following code came from perlmonks which is a very reputable reference for anything to do with programming in perl. Here is the subroutine I chose to use. Article was written in 2002.

use Math::Trig
sub FlatEarth {
my ($lat1, $long1, $lat2, $long2) = @_;
my $r=3956; my $a = (pi/2)- deg2rad($lat1);
my $b = (pi/2)- deg2rad($lat2)
my $c = sqrt($a**2 + $b**2 - 2 * $a *$b *cos(deg2rad($long2)-deg2rad($long1)));
my $dist = $c * $r; return $dist;

Via Finding the Distance between longitude and latitude pairs.

The above code seems to work.  Most of the calculations I needed to do were under a mile.

permission denied for file write

Redirections such as > or | are performed by the running shell, before it invokes sudo.

You have to either use

sudo sh -c "echo blah > /proc/blah", or run a root shell with sudo -s.

via linux – Bash: permission denied for file write – Super User.

This had me stumped until the greatness of google divined the answer and why my user script couldn’t write to a root owned file using plain old sudo.  After figuring this out I also realized I don’t need to write to a root owned file after all but I found this solution interesting.

Disable NetBIOS in W2K/XP/2003

NetBIOS is an ancient session-level interface and transport protocol developed by IBM to network together PCs. It is a broadcast-based, non-routable and insecure protocol, and it scales poorly mostly because it was designed with a flat namespace. Since the late 1980s Microsoft has adopted NetBIOS for their LAN Manager product, and from there it found its way into early versions of Windows and all the way into Windows NT.

via Disable NetBIOS in W2K/XP/2003.

Works with Windows 7 and got rid of all NBNS traffic for me on a per interface basis.  I have netbios disabled on the wireless interface  because wireless should be considered insecure and this NetBios traffic likes to broadcast to everyone your position which IMHO is not good.  Run silent, run deep.

Set Up the Master Boot Record

When setting up the Master Boot Record, you need to enter appropriate partition information. In this example, Grub is in the first partition on the first hard drive, which is (hd0,0) in Grub. Change this to whatever partition Grub is in.

After getting the Grub prompt, type:

root (hd0,0)
setup (hd0)

via Set Up the Master Boot Record.

This has been sitting as draft since August 5 and works in setting the MBR on a hard drive and since things like this can be easily forgotten, it has become a reference.  Even Testdisk couldn’t  write the MBR correctly when I tried to transfer a Fedora14 VM onto a real hard drive.  After setting the MBR and getting it to boot the network and graphic interfaces required manual intervention.  I’m not convinced transferring a virtual image to a physical image is much of a time saver.

Note: Not all installations have grub installed by default.  The command to get the grub prompt is /sbin/grub run as root.