我正在编写一个 bash 脚本来增加 VPS 服务器上的 /tmp ,我想让它更清洁/更高效,而无需为选择的任何选项重复相同的命令。这是它现在的结构:
#!/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
我基本上只想在此过程中启动一次冗余命令。你能给我一个或多个关于最好的方法的想法吗?
谢谢。