Hi onelife
Just a few comments. You need to learn proper indentation. If I had to apply a name to your formatting, it would probably be called
SRI (Semi Random Indentation)
. What you have makes it difficult to follow which lines of code belong to which if clause. Here
is my suggestion of how to make it more readable:
#!/bin/sh
if [ -f /mnt/mmcblk0p2/tce/md5mydata ] ; then
sudo cat /mnt/mmcblk0p2/tce/md5mydata | md5sum -c > /tmp/md5sum
if grep "FAILED" /tmp/md5sum ; then
echo "MD5SUM FAILED"
if [ -f /mnt/mmcblk0p2/tce/mydata.corrupt ] ; then
echo "NO BACKUP AVAILABLE - GOING INTO RESCUE"
sudo /usr/local/etc/init.d/openssh start
sleep 20
sudo sed -i -e "s|#PermitEmptyPasswords no|PermitEmptyPasswords yes|" /usr/local/etc/ssh/sshd_config
sudo /usr/local/etc/init.d/openssh restart
sleep 1
exit
else
sudo mv -f /mnt/mmcblk0p2/tce/mydata.tgz /mnt/mmcblk0p2/tce/mydata.corrupt
sleep 1
sudo mv -f /mnt/mmcblk0p2/tce/mydatabk.tgz /mnt/mmcblk0p2/tce/mydata.tgz
sleep 1
sync
sleep 2
sudo reboot
fi
else
echo "MD5SUM PASSED"
fi
else
echo "NO MD5SUM - CHECKING SYSTEM"
fi
exit
Now you can see where each if clause ends and which else belongs to which if. And don't use the spacebar for indentation, that's
what the Tab key is for.
What's with all the sleep commands here:
else
sudo mv -f /mnt/mmcblk0p2/tce/mydata.tgz /mnt/mmcblk0p2/tce/mydata.corrupt
sleep 1
sudo mv -f /mnt/mmcblk0p2/tce/mydatabk.tgz /mnt/mmcblk0p2/tce/mydata.tgz
sleep 1
sync
sleep 2
sudo reboot
fi
The kernel should handle completing the first move before the second one starts.
Does it not work correctly like this:
else
sudo mv -f /mnt/mmcblk0p2/tce/mydata.tgz /mnt/mmcblk0p2/tce/mydata.corrupt
sudo mv -f /mnt/mmcblk0p2/tce/mydatabk.tgz /mnt/mmcblk0p2/tce/mydata.tgz
sync
sudo reboot
fi
The same basic comments apply to your other script.
Will it not work if you change this:
filetool.sh -b
sleep 2
sync
sleep 2
sudo chmod 777 /mnt/mmcblk0p2/tce/md5mydata
sudo md5sum /mnt/mmcblk0p2/tce/mydata.tgz > /mnt/mmcblk0p2/tce/md5mydata
to this:
filetool.sh -b
sudo chmod 777 /mnt/mmcblk0p2/tce/md5mydata
sync
sudo md5sum /mnt/mmcblk0p2/tce/mydata.tgz > /mnt/mmcblk0p2/tce/md5mydata