Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

check if a device is defined or available

Status
Not open for further replies.

MoreFeo

Technical User
Nov 29, 2002
547
ES
Hi, I'm trying to make a script that has to check if a device such as the cd or rmt is available, or at least defined.
So I thought about looking for /dev/cd0 or /dev/rmt0 with:

if [ ! -f /dev/$1 ]
then
echo "Error, no such device /dev/$1"

$1 should be rmt0 or cd0.
I've tried with rmt0, that is in a defined state, and ls /dev shows there is a /dev/rmt0, but when I run the script it shows the "Error, no such device /dev/rmt0" sentence.

So I suppose that -f only works with plain files, not with /dev ones. Does anyone know how I can check this? It's AIX 5300-4.

Thanks
 
Like so?

Code:
for DEV in rmt0 cd0
do
 DEVSTAT=$(lsdev -C -F status -l ${DEV} 2>/dev/null)

 case "${DEVSTAT}" in
  '')
   echo "${DEV} undefined"
   ;;
  Defined)
   echo "${DEV} defined, not usable"
   ;;
  Available)
   echo "${DEV} available for use"
   ;;
 esac
done


HTH,

p5wizard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top