I'm working on a bash script to increase /tmp on a VPS server and I'd like to make it cleaner/more efficient without the need to repeat the same commands for whichever option is picked. Here's how it's structured right now:
#!/bin/bash
showMenu () {
echo "1) Increase /tmp size to 1 GB"
echo "2) Increase /tmp size to 2 GB"
echo "3) Quit"
}
while [ 1 ]
do
showMenu
read CHOICE
case "$CHOICE" in
"1")
/etc/init.d/mysql stop
/etc/init.d/httpd stop
/etc/init.d/cpanel stop
cp -af /var/tmp /var/tmp.bak
umount -l /var/tmp
umount -l /tmp
rm -f /usr/tmpDSK
dd if=/dev/zero of=/usr/tmpDSK bs=1M count=1k
mkfs.ext3 -F /usr/tmpDSK
mount -t ext3 -o nosuid,noexec,loop /usr/tmpDSK /tmp
mount -o bind,noexec,nosuid /tmp /var/tmp
cp -a /var/tmp.bak/* /tmp/
rm -rf /var/tmp.bak/
chmod 1777 /tmp
/etc/init.d/mysql start
/etc/init.d/httpd start
/etc/init.d/cpanel start
df -h
exit 1
;;
"2")
/etc/init.d/mysql stop
/etc/init.d/httpd stop
/etc/init.d/cpanel stop
cp -af /var/tmp /var/tmp.bak
umount -l /var/tmp
umount -l /tmp
rm -f /usr/tmpDSK
dd if=/dev/zero of=/usr/tmpDSK bs=1M count=2k
mkfs.ext3 -F /usr/tmpDSK
mount -t ext3 -o nosuid,noexec,loop /usr/tmpDSK /tmp
mount -o bind,noexec,nosuid /tmp /var/tmp
cp -a /var/tmp.bak/* /tmp/
rm -rf /var/tmp.bak/
chmod 1777 /tmp
/etc/init.d/mysql start
/etc/init.d/httpd start
/etc/init.d/cpanel start
df -h
exit 1
;;
"3")
exit 1
;;
esac
done
I basically want to only initiate the redundant commands once during this process. Can you give me an idea or ideas on the best way to do this?
Thanks.