In a shell script you’re probably testing a variable against some constant or another variable, but why not run a command in a subshell and compare the output? You could even compare the output of two subshell commands! I guess most of the time i’m doing something like this i’m using perl or python. But I needed a way to double check which disk had a powerpc boot partition on it before copying it over to a blank disk and I didn’t have much to work with on those old boards, so I whipped this up right quick:
#!/bin/sh
#check to see if sda has a PPC boot partition
if [ "`/sbin/fdisk -l /dev/sda | grep PPC`" == "" ]; then
if [ "`/sbin/fdisk -l /dev/sdb | grep PPC`" == "" ]; then
echo “both disks have PPC boot partitions”
exit 1;
else
echo “run this: dd if=/dev/sdb of=/dev/sda”
fi
else
if [ "`/sbin/fdisk -l /dev/sdb | grep PPC`" == "" ]; then
echo “run this: dd if=/dev/sda of=/dev/sdb”
else
echo “both disks have PPC boot partitions”
exit 1;
fi
fi
Shell scripting if-then-else tests with commands embedded in backticks. Why? Because i’m messing with some old power pc blades running 2.4 kernels with no modern day apps like ssh, rsync, or python. I don’t know why I didn’t think of this before now?
http://blog.rootninja.com/wp-content/uploads/2008/09/rootninja_80×151.jpg” alt=”root|ninja” width=”80″ height=”15″ />