顯示具有 Bash script 標籤的文章。 顯示所有文章
顯示具有 Bash script 標籤的文章。 顯示所有文章

How to use fdisk within a shell script


$vim test_fdisk
=====================================
=====================================
$chmod +x test_fdisk
$./test_fdisk 1 +1G

死迴圈

while list do list done
当list为True时,该圈会不停地执行。
例一 : 无限回圈写法
#!/bin/sh

while : ; do
echo "do something forever here"
sleep 5
done

例二 : 强迫把pppd杀掉。
#!/bin/sh

while [ -f /var/run/ppp0.pid ] ; do
killall pppd
done



--------------------------------------------------------------------------------

until list do list done
当list为False(non-zero)时,该圈会不停地执行。
例一 : 等待pppd上线。
#!/bin/sh
until [ -f /var/run/ppp0.pid ] ; do
sleep 1
done

Verifying a filesystem mount in a bash script

Sometimes you need to check if a drive is properly mounted before performing a scripted operation. A few Linux tools can detect whether they are on an NFS share or not, but there is no shorthand to find if a certain path is the mounted filesystem or an empty unmounted directory.

The easiest method appears to be using grep to evaluate the output of df or mount. Instead of the lines containing the string, the quiet mode of grep (-q option) returns an error code representing whether the string was found. This can be placed in a conditional inside a shell script like in the following example:

if df |grep -q '/mnt/mountpoint$'
then
echo "Found mount point, running task"
# Do some stuff
else
echo "Aborted because the disk is not mounted"
# Do some error correcting stuff
exit -1
fi

虹光大成就-密教灌頂(一)