-- ==================================================================
--	ASMCMD Disk Group Management Commands
-- ==================================================================
Command				Description
-------------		--------------------------------------------
amdu_extract		Extracts a file from a disk group.
cd					Changes the current directory to the specified directory.
cp					Enables you to copy files between disk groups, and between a disk group and the operating system.
du					Displays the total disk space occupied by files in the specified Oracle ASM directory and all of its subdirectories, recursively.
find				Lists the paths of all occurrences of the specified name (with wildcards) under the specified directory.
ls					Lists the contents of an Oracle ASM directory, the attributes of the specified file, or the names and attributes of all disk groups.
lsof				Lists the open files.
mkalias				Creates an alias for system-generated file names.
mkdir				Creates Oracle ASM directories.
pwd					Displays the path of the current Oracle ASM directory.
rm					Deletes the specified Oracle ASM files or directories.
rmalias				Deletes the specified alias, retaining the file that the alias points to.

-- ==================================================================
--	ASMCMD Disk Group Management Commands
-- ==================================================================
Command				Description
-------------		--------------------------------------------
chdg				Changes a disk group (add, drop, rebalance, or migrate on the Exadata appliance).
chkdg				Checks or repairs a disk group.
dropdg				Drops a disk group.
iostat				Displays I/O statistics for disks.
lsattr				Lists the attributes of a disk group.
lsdg				Lists disk groups and their information.
lsdsk				Lists disks Oracle ASM disks.
lsod				Lists open devices.
md_backup			Creates a backup of the metadata of mounted disk groups.
md_restore			Restores disk groups from a backup of the metadata.
mkdg				Creates a disk group.
mount				Mounts a disk group.
offline				Offlines a disk or a failure group.
online				Onlines a disk or a failure group.
rebal				Rebalances a disk group.
remap				Relocates data in a range of physical blocks on a disk.
setsparseparent		Sets the parent for a sparse child file.
setattr				Sets attributes in a disk group.
stamp				Stamps the disk, site, and failure group labels in disk headers.
stamplist			Displays the disk, site, and failure group labels in disk headers.
umount				Dismounts a disk group.

-- ==================================================================
--	ASMCMD Disk Group Management Commands
-- ==================================================================
Command				Description
-------------		--------------------------------------------
chtmpl				Changes the attributes of a template.
lstmpl				Lists disk group templates.
mktmpl				Adds a template to a disk group.
rmtmpl				Removes a template from a disk group.

-- ==================================================================
--	ASMCMD File Access Control Commands
-- ==================================================================
Command				Description
-------------		--------------------------------------------
chgrp				Changes the user group of a file or list of files.
chmod				Changes permissions of a file or list of files.
chown				Changes the owner of a file or list of files.
groups				Lists the user groups to which a user belongs.
grpmod				Adds or removes users from an existing user group.
lsgrp				Lists user groups.
lsusr				Lists users in a disk group.
mkgrp				Creates a new user group.
mkusr				Adds a user to disk group.
passwd				Changes the password of a user.
rmgrp				Deletes a user group.
rmusr				Deletes a user from a disk group.
rpusr				Replaces one a user with another in a disk group.

-- ==================================================================
--	List all diskgroups:
-- ==================================================================
# To List the current directory.
ASMCMD> ls
ASMCMD> ls -l
	State 	Type 	Rebal 	Name
	MOUNTED EXTERN 	N 		DATA/
	MOUNTED EXTERN 	N 		FRA/

ASMCMD> lsdg
	State 	Type 	Rebal 	Sector 	Block 	AU 		Total_MB Free_MB Req_mir_free_MB Usable_file_MB Offline_disks 	Voting_files 	Name
	MOUNTED EXTERN 	N 		512 	4096 	1048576 18426 	 15138 	 0			     15138 			0		 		N	 			DATA/

# Include dismounted diskgroups:
ASMCMD> lsdg --discovery

# List diskgroups across all nodes of cluster:
ASMCMD> lsdg -g --discovery

# To list a particular diskgroup.
ASMCMD> lsdg DATA

#To list Mounted ASM disks.
ASMCMD> lsdsk
	Path
	/dev/oracleasm/disks/DATA01
	/dev/oracleasm/disks/FRA01

ASMCMD> lsdsk -k 
Total_MB Free_MB OS_MB Name Failgroup Library Label UDID Product Redund Path
18426 15138 18426 DATA01 DATA01 ASM Library – Generic Linux, version 2.0.12 (KABI_V2) DATA01 UNKNOWN /dev/oracleasm/disks/DATA01
8189 7654 8189 FRA01 FRA01 ASM Library – Generic Linux, version 2.0.12 (KABI_V2) FRA01 UNKNOWN /dev/oracleasm/disks/FRA01

# List disks of a diskgroup(DATA) with free and total MB
ASMCMD> lsdsk -k -G DATA
Total_MB Free_MB OS_MB Name Failgroup Library Label UDID Product Redund Path
18426 15138 18426 DATA01 DATA01 ASM Library – Generic Linux, version 2.0.12 (KABI_V2) DATA UNKNOWN /dev/oracleasm/disks/DATA01
Now it’s showing details of “DATA01” disk only.

# List disks of a diskgroup(CDATA) with group and disk number
ASMCMD> lsdsk -p -G CDATA

# List disks with disk creation date 
ASMCMD> lsdsk -t -G CDATA

# List candidiate disks only

ASMCMD>  lsdsk #candidate -k

# List member disks only
ASMCMD>  lsdsk #candidate -p

-- ==================================================================
--	 Get attributes of ASM diskgroups
-- ==================================================================
# SYNTAX: ASMCMD> lsattr -l +diskgroup/path
ASMCMD> lsattr -lm 

# List attribute of specific diskgroup(DMARCH)
ASMCMD> lsattr -lm -G  DMARCH
	Group_Name  Name                     Value       RO  Sys
	DMARCH      access_control.enabled   FALSE       N   Y
	DMARCH      access_control.umask     066         N   Y
	DMARCH      au_size                  1048576     Y   Y
	DMARCH      cell.smart_scan_capable  FALSE       N   N

# List attributes with specific pattern
ASMCMD> lsattr -lm %au_size%
	Group_Name  Name     Value    RO  Sys
	CDATA       au_size  1048576  Y   Y
	BDM         au_size  1048576  Y   Y
	CRMG        au_size  1048576  Y   Y
	PMARCH      au_size  1048576  Y   Y
	BCMS        au_size  1048576  Y   Y

-- ==================================================================
--	 Unmount Diskgroup:
-- ==================================================================
# unmount command works only on the local node. 
# So if you want to unmount the diskgroup from all nodes of cluster, then run this command from all the nodes.

# unmount all diskgroups
ASMCMD> umount -a

#- unmount specific diskgroup(ARCH)
ASMCMD> umount ARCH

-- ==================================================================
--	 Mount Diskgroup:
-- ==================================================================
#Mount command works only on the local node. 
#So if you want to Mount the diskgroup from all nodes of cluster, then run this command from all the nodes.

# mount all diskgroups on local node
ASMCMD> mount -a

#- mount a specific diskgroup on local node
ASMCMD> mount FRA

-- ==================================================================
--	 Rebalance a Diskgroup:
-- ==================================================================
# here asm_power_limit is 8 and diskgroup is ARCH

ASMCMD> rebal #power 8 ARCH
Rebal on progress.

# Monitor progress

ASMCMD> lsop
	Group_Name  Pass       State  Power  EST_WORK  EST_RATE  EST_TIME
	ARCH        COMPACT    RUN    8      0         16831     0
	ARCH        REBALANCE  DONE   8      0         0         0

-- ==================================================================
--	 Get Password File of Database
-- ==================================================================
ASMCMD> pwget #dbuniquename PROD
	+CDATA/PROD/PASSWORD/pwdPROD.256.899912377

-- ==================================================================
--	 Get Password File of ASM
-- ==================================================================
ASMCMD> pwget #asm
	+MGMT/orapwASM

-- ==================================================================
--	 Get ASM Template Info of a Diskgroup:
-- ==================================================================
ASMCMD> lstmpl -l -G ARCH
	Group_Name  Group_Num  Name                       Stripe  Sys  Redund  PriReg  MirrReg
	ARCH        1          ARCHIVELOG                 COARSE  Y    UNPROT  COLD    COLD
	ARCH        1          ASMPARAMETERFILE           COARSE  Y    UNPROT  COLD    COLD
	ARCH        1          AUDIT_SPILLFILES           COARSE  Y    UNPROT  COLD    COLD
	ARCH        1          AUTOBACKUP                 COARSE  Y    UNPROT  COLD    COLD
	ARCH        1          AUTOLOGIN_KEY_STORE        COARSE  Y    UNPROT  COLD    COLD
	ARCH        1          BACKUPSET                  COARSE  Y    UNPROT  COLD    COLD

-- ==================================================================
--	 Check whether Flex ASM is Enabled or Disable
-- ==================================================================
ASMCMD> showclustermode
	ASM cluster : Flex mode disabled

-- ==================================================================
--	Check cluster state
-- ==================================================================
ASMCMD> showclusterstate
	Normal

-- ==================================================================
--	 View ASM version:
-- ==================================================================
ASMCMD> showversion
	ASM version         : 12.1.0.2.0

$ asmcmd -V
	asmcmd version 11.2.0.0.0

-- ==================================================================
--	 Get ASM spfile location:
-- ==================================================================
ASMCMD> spget
	+MGMT/PROD-cluster/ASMPARAMETERFILE/registry.253.899644763

#To get information about OracleASM ServerParameter file.
#This will show you the location of spfile for ASM instance.
ASMCMD> spget
	+DATA/rc-scan/asmparameterfile/registry.253.986765603

-- ==================================================================
--	 Take backup of ASM spfile:
-- ==================================================================
# copy backup of spfile to a specific location
ASMCMD> spbackup +MGMT/PROD-cluster/ASMPARAMETERFILE/registry.253.899644763 /home/oracle/asmspfile.ora

-- ==================================================================
--	 Find clients connected to a diskgroup:
-- ==================================================================
ASMCMD> lsct DMARCH
	DB_Name  Status     Software_Version  Compatible_version  	Instance_Name  	Disk_Group
	PROD  CONNECTED        12.1.0.2.0          12.1.0.2.0  		PROD1       	DMARCH

-- ==================================================================
--	 Get ASM diskstring
-- ==================================================================
ASMCMD> dsget
	parameter:ORCL:*
	profile:ORCL:*

-- ==================================================================
--	 List ASM users with password
-- ==================================================================
ASMCMD> lspwusr
	Username sysdba sysoper sysasm
		 SYS   TRUE    TRUE   TRUE
	 ASMSNMP   TRUE   FALSE  FALSE

-- ==================================================================
--	 List open files related to a database
-- ==================================================================
ASMCMD>lsof #dbname PROD

ASMCMD>lsof -G ARCH

#To list currently open files by all instances in ASM

ASMCMD [+] > lsof
	DB_Name Instance_Name Path
	PROD 	PROD		  +DATA/PROD/CONTROLFILE/current.265.987302781
	PROD	PROD		  +DATA/PROD/DATAFILE/sysaux.269.987302597
	PROD	PROD		  +DATA/PROD/DATAFILE/system.261.987302651
	PROD	PROD		  +DATA/PROD/DATAFILE/undotbs1.268.987302719
	PROD	PROD		  +DATA/PROD/DATAFILE/users.272.987302717
	PROD	PROD		  +DATA/PROD/ONLINELOG/group_1.264.987302785
	PROD	PROD		  +DATA/PROD/ONLINELOG/group_2.263.987302789
	PROD	PROD		  +DATA/PROD/ONLINELOG/group_3.262.987302793
	PROD	PROD		  +DATA/PROD/TEMPFILE/temp.273.987302813
	PROD	PROD		  +FRA/PROD/CONTROLFILE/current.256.987302781
	PROD	PROD		  +FRA/PROD/ONLINELOG/group_1.259.987302787
	PROD	PROD		  +FRA/PROD/ONLINELOG/group_2.258.987302791

-- ==================================================================
--	 Check filter driver is enabled or not:
-- ==================================================================
ASMCMD> afd_state
	ASMCMD-9526: The AFD state is 'NOT INSTALLED' and filtering is 'DEFAULT' on host 'b20e4bay01'

-- ==================================================================
--	 List filter driver disks(if enabled)
-- ==================================================================
ASMCMD> afd_lsdsk

-- ==================================================================
--	 Get filter driver ASM diskstring
-- ==================================================================
ASMCMD> afd_dsget
	AFD discovery string:

-- ==================================================================
--	 To get Input/Output State details of disks
-- ==================================================================
ASMCMD> iostat
	Group_Name 	Dsk_Name 	Reads 		Writes
	DATA 		DATA01 		5450240 	12764160
	FRA 		FRA01 		98304 		4096
#Here Group_Name shows, which ASM diskgroup this disk belongs to. We can see Reads/Writes information in bytes.

ASMCMD> iostat -G FRA
	Group_Name 	Dsk_Name Reads 	Writes
	FRA 		FRA01 	 98304 	4096

# To retrieve information of Reads/Writes Error.
#This will show you IO erros of disk.
ASMCMD> iostat -e
	Group_Name 	Dsk_Name 	Reads 	Writes 		Read_Err Write_Err
	DATA 		DATA01 		5450240 13280256 	0 		 0
	FRA 		FRA01 		98304 	4096 		0 		 0

# To get Time Statistics, Read Time & Write Time.
ASMCMD> iostat -e -t
	Group_Name 	Dsk_Name Reads 	 Writes 	Read_Err Write_Err Read_Time Write_Time
	DATA 		DATA01 	 5450240 13624320 	0 		 0 .811 1.37 FRA FRA01 98304 4096 0 0 .011 0

-- ==================================================================
--	To print current directory path in ASMCMD, using -p argument.
-- ==================================================================
[oracle@node1 ~]$ asmcmd -p
ASMCMD [+] >

We can see It is showing ‘+’ that is Root Directory.
Let’s navigate to sub-directory.
ASMCMD [+] > ls
	DATA/
	FRA/
	
ASMCMD [+] > cd +DATA/PROD/DATAFILE
ASMCMD [+DATA/PROD/DATAFILE] > ls
	EXAMPLE.264.986768097
	SYSAUX.257.986767995
	SYSTEM.256.986767993
	TBS.269.986769231
	UNDOTBS1.258.986767995
	UNDOTBS2.265.986768163
	USERS.259.986767995

-- ==================================================================
--	 To check permissions on file
-- ==================================================================
ASMCMD [+DATA/PROD/DATAFILE] > ls –permission
	User Group Permission Name
	rw-rw-rw- EXAMPLE.264.986768097
	rw-rw-rw- SYSAUX.257.986767995
	rw-rw-rw- SYSTEM.256.986767993
	rw-rw-rw- TBS.269.986769231
	rw-rw-rw- UNDOTBS1.258.986767995
	rw-rw-rw- UNDOTBS2.265.986768163
	rw-rw-rw- USERS.259.986767995
	
-- ==================================================================
--	 To Check disk usage
-- ==================================================================
ASMCMD [+DATA] > du
	Used_MB  Mirror_used_MB
	3154 	 3154

-- ==================================================================
--	 To Find file with name
-- ==================================================================
#SYNTAX: ASMCMD> find +diskgroup path

ASMCMD [+DATA] > find + system*
+DATA/PROD/DATAFILE/SYSTEM.256.986767993

hostgator