上記の広告は1ヶ月以上更新のないブログに表示されています。
新しい記事を書く事で広告が消せます。

Shell script to unmount device

In Gnome and so on, if you right-click icon in desktop for some partition in a device, you will see "Safely remove the media" and so on.
If you click it, all partitions in the device will be unmounted and you can remove the device.

In openbox and so on with thunar (version 1.0.2), there are not such menu.

The following script support you to unmount all the partitions in the device you want to remove.

============================================================
#!/bin/bash
if [ $USER = "root" ];then
langbackup=$LANG
LANG=C
devicelist=$(fdisk -l|grep "^Disk /dev/"|sort|tr ' ' '_')
list1=""
i=0
for a in $devicelist;do
list1="$list1 $i $a"
i=$(expr $i + 1)
done
device2=$(zenity --text="Please select the device you want to remove" --list --radiolist --column="check" --column="info." $list1|sed -e "s/Disk_//"|cut -c 1-8)
if [ -z "$device2" ];then
zenity --warning --text="Nothing selected. I will abort without unmounting."
LANG=$langbackup
exit 1
fi
mountlist=$(mount|grep ^$device2|cut -d " " -f3)
if [ -z $mountlist ];then
zenity --warning --text="No partitions in:
$(fdisk -l|grep "^Disk $device2")
is mounted. You can remove $device2."
LANG=$langbackup
exit 0
fi
pid=""
for mountpart in $mountlist;do
thunar $mountpart & pid="$pid $!"
done
sleep 1
zenity --question --text="Do you want to unmount the partitions ?"
if [ $? = "1" ];then
echo "Nothing has been unmounted. I am aborting according to your request."
else
zenity --warning --text="Data are now written to devices. Please wait." & pid1="$!"
sync
kill $pid1
umount $mountlist
fi
kill $pid
LANG=$langbackup
if [ -n "$(mount|grep ^$device2)" ];then
zenity --warning --text="The following partitions are mounted.
$device2
$(mount|grep ^$device2|cut -d" " -f1-3)"
exit 1
else
zenity --warning --text="All partitions in:
$(fdisk -l |grep "^Disk $device2")
was unmounted. You can remove $device2"
exit 0
fi
else
gksu -m "Please type root password to get the information of devices connected." bash $0
exit 0
fi
====================================
Make a text file with the contents shown above. Save it and make it executable.
Double click the saved file to use.

You need zenity package.

テーマ : Linux
ジャンル : コンピュータ

プロフィール

kiyoshi

Author:kiyoshi
FC2ブログへようこそ!

最新記事
最新コメント
最新トラックバック
月別アーカイブ
カテゴリ
検索フォーム
RSSリンクの表示
リンク
ブロとも申請フォーム

この人とブロともになる

QRコード
QRコード
since 2011/9/25
現在の閲覧者数:
上記広告は1ヶ月以上更新のないブログに表示されています。新しい記事を書くことで広告を消せます。