Running ASMCMD in Noninteractive Mode

In noninteractive mode, you run a single ASMCMD command by including the command and command options on the command line when invoking ASMCMD. ASMCMD runs the command, generates output if any, and then exits. The noninteractive mode is especially useful for running scripts.

On most operating systems, wildcard characters must be enclosed in quotes when running ASMCMD commands in noninteractive mode.

To run ASMCMD in noninteractive mode where command is any valid ASMCMD command and options is a list of command options, at the command prompt enter the following:

asmcmd command options

In noninteractive mode, ASMCMD returns the codes listed in Table 10-3.


Table 10-3 ASMCMD return codes

Type Return Code Description

General

0

No issues for the command.

General

1

Internal error.

General

255 or -1

External user error as returned by a command.

lsdsk

0

Results include member disks only.

lsdsk

1

Results include candidate disks only.

lsdsk

2

Results include both member and candidate disks.


Example 10-2 shows how to run ASMCMD in the noninteractive mode. The first command runs the ls command to list the disk groups for the Oracle ASM instance. The second command redirects the output of the lsod command to the my_lsod_test file. The third command runs lsdsk using a pattern with a wildcard character to list specific disks in the data disk group. Note that wildcard characters must be enclosed in quotes when running ASMCMD in noninteractive mode on most operating systems.

Example 10-3 raises an error with an incorrect disk group name and the return code equal (255) is displayed.

Example 10-4 shows an example of ASMCMD commands run in noninteractive mode inside a script.

Example 10-2 Running ASMCMD commands in noninteractive mode

$ asmcmd ls -l
State    Type    Rebal  Name
MOUNTED  NORMAL  N      DATA/
MOUNTED  NORMAL  N      FRA/

$ asmcmd lsod --suppressheader -G data > my_lsod_test

$ asmcmd lsdsk -G data '/devices/diska*'
Path
/devices/diska1
/devices/diska2
/devices/diska3

Example 10-3 Displaying a return code when running ASMCMD in noninteractive mode

$ asmcmd ls -l dat
ASMCMD-08001: diskgroup 'dat' does not exist or is not mounted

$ echo $?
255

Example 10-4 Running ASMCMD commands in a script

#!/bin/sh
for ((i = 1; i <=3; i++))
 do
   asmcmd lsdsk -G data '/devices/diska'$i
done

$ ./asmcmd_test_script
Path
/devices/diska1
Path
/devices/diska2
Path
/devices/diska3