| Current File : //usr/ddu/scripts/find_media.sh |
#!/usr/bin/ksh93
#
# Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
#
# Description: Check the mounted removable media
# on the system. For example, cd/dvd,
# usb disk etc.
#
# Set trap
#
trap 'clean_up;exit 10' KILL INT
trap 'clean_up' EXIT
PATH=/usr/bin:/usr/sbin:$PATH; export PATH
LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/ddu/lib; export LD_LIBRARY_PATH
typeset -r base_dir=$(dirname $0)
typeset -r platform=$(uname -p)
typeset -r bin_dir=$(echo $base_dir | sed 's/scripts$/bin\//')${platform}
typeset err_log=/tmp/ddu_err.log
#######################################################################
# clean_up
# This function attempst to clean up any resources this script
# could generate. Depending on where in the script this function
# is involked some resouces may not be there to cleanup, but
# that will not adversely effect anything.
#
# This function is not defined using the function keyword
# to avoid an exit loop.
#
# Input: none
# Returns: none
#
#######################################################################
clean_up()
{
{
rm -f $rf_file
}>/dev/null 2>&1
}
#
# Probe for mounted removable media and output the info with the format:
# device path:device name:mount status:mount path
#
function probe_s
{
rf_file=/tmp/find.media.$$
ddu_tmp_file=/tmp/ddu_tmp_fie.$$
typeset dev_path name mp dev_name
#
#Ouput cd devices
#
#
# Set carriage return to IFS
#
IFS='
'
pfexec ${bin_dir}/cd_detect -l | \
awk -F'|' '{print $1,"|",$2}' >$ddu_tmp_file 2>>$err_log
if [ $? != 0 ]; then
print "$0: ${bin_dir}/cd_detect -l failed." >>$err_log
exit 1
fi
for i in $(cat $ddu_tmp_file); do
dev_path=$(echo $i | cut -d'|' -f1 | sed 's/rdsk/dsk/' | tr -d " ")
name=$(echo $i | cut -d'|' -f2 | tr -d " ")
/usr/sbin/mount | grep $dev_path >/dev/null 2>&1
if [ $? -eq 0 ]; then
mp=$(/usr/sbin/mount | grep $dev_path 2>/dev/null \
| nawk -F" on " '{print $1}')
if [ $? == 0 ]; then
print -u1 "${dev_path}|${name}|Mounted|$mp"
fi
fi
done
rm -f $ddu_tmp_file >/dev/null 2>&1
#
#Output Usb Disk
#
pfexec ${bin_dir}/hd_detect -r >$rf_file 2>>$err_log
if [ $? != 0 ]; then
echo "$0: ${bin_dir}/hd_detect -r failed." >>$err_log
exit 1
fi
for i in \
$(pfexec /usr/sbin/format -e 2>/dev/null </dev/null \
| sed -n '/^ /p' | grep "^ *[0-9]" \
| sed 's/^ *//g' | awk '{print $2}'); do
#
# Validate the output format
#
echo $i | grep '^[a-z][0-9]' >/dev/null 2>&1
if [ $? != 0 ]; then
print "$i is not a valid storage device name." >>$err_log
continue
fi
cat $rf_file | grep $i >/dev/null 2>&1
#
# Use mount command to check mount point
#
if [ $? -eq 0 ]; then
dev_path="/dev/dsk/${i}"
dev_name=$(cat $rf_file | grep $i | cut -d: -f1)
/usr/sbin/mount | grep $dev_path >/dev/null 2>&1
if [ $? -eq 0 ]; then
for i in $(/usr/sbin/mount | grep $dev_path 2>/dev/null); do
dev_path_1=$(echo $i | nawk -F" on " '{print $2}' \
| awk '{print $1}')
mp=$(echo $i | nawk -F" on " '{print $1}')
print -u1 "${dev_path_1}|${dev_name}|Mounted|$mp"
done
fi
fi
done
rm -f $rf_file >/dev/null 2>&1
}
#Main()
case $# in
1) if [ $1 != "probe_s" ]; then
exit 1
fi
$1
;;
*) exit 1
;;
esac