Syntax
diskspace logical-name[=path] [qty=nnn{b|k|m|g}] [cond={GT|LT}]
Description
The diskspace command retrieves the amount of space available on a volume or file system.
UDM executes the command on the system identified by the logical-name parameter. This parameter must match a logical name specified in the open command. Use "local" to refer to the primary server session in a two-party transfer.
To retrieve the available space for an entire volume or file system, simply specify any directory path that exists there. If no path is specified, UDM uses the current working directory to determine which device to check.
Whenever UDM executes the diskspace command, it stores the number of available bytes in the _diskspace built-in variable. The .kb
, .mb
, and .gb
attributes provide access to the available quantity in kilobytes, megabytes, or gigabytes. For example, the amount of available space in megabytes is accessed using $(_diskspace.mb).
While the $(_diskspace) variable may be used in calculations and evaluations, the diskspace command provides the optional qty and cond parameters to quickly test whether the amount of available space is more or less than a specified quantity. UDM sets the _lastrc built-in variable to 0 (zero) if the result of the test evaluates to true. UDM sets $(_lastrc.result) to a non-zero value when the test evaluates to false.
The amount of space that the diskspace command will check for is specified with the qty parameter. The quantity can be expressed in terms of bytes, kilobytes, megabytes and gigabytes. If no unit is specified, the default is bytes.
The optional cond parameter specifies whether the diskspace command will test for available space that is greater than (GT, the default) or less than (LT) the specified quantity (qty).
If the test succeeds, diskspace sets $(_lastrc.result) to 0 (zero) and $(_lastrc.message) to "SUCCESS". If the test fails, diskspace sets $(_lastrc.result) to non-zero and $(_lastrc.message) to "ERROR".
For example, given a diskspace command where qty=100m and cond=GT, UDM sets $(_lastrc.result) to 0 (zero) if more than 100 megabtyes (MB) of space is available. If exactly 100MB or less is available, then $(_lastrc.result) is set to a non-zero value. Conversely, if qty=100m and cond=LT, UDM sets $(_lastrc.result) to 0 only when there is less than 100MB space available.
Parameters
Parameter | Description |
---|---|
logical_name | Name of the system where UDM checks available space. If path is specified, diskspace checks the volume or file system where that directory resides. Otherwise, the current working directory is used. Note On z/OS and IBM i, the current file system must be set to HFS (see the filesyscommand). |
qty | Amount of space that diskspace should look for. To specify a unit for the quantity, add one of the following letters to the quantity amount:
If no unit is specified, the default (b - bytes) is used. If no quantity is specified, diskspace displays the available space. |
cond | Instructs diskspace to check for an amount that is greater than (GT) or less than (LT) the specified quantity. This parameter is optional. If no condition is specified, GT is used. |
Examples
The following example displays the amount of space available on the volume or file system that contains the directory c:\somedir
.
open dst=ipaddr user=uid pwd=password diskspace dst=c:\somedir
The following example verifies that the available space for the volume or file system that contains the current working directory is greater than 10GB.
open dst=ipaddr user=uid pwd=password diskspace dst qty=10g if $(_lastrc.result) EQ 0 echo "At least 10 GB is available" else echo "Less than 10 GB is available" end
The statements below repeat the previous example using the $(_diskspace) built-in variable with the .gb
attribute.
open dst=ipaddr user=uid pwd=password diskspace dst if $(_diskspace.gb) GE 10 echo "At least 10 GB is available" else echo "Less than 10 GB is available" end
The following example uses diskspace in the context of a forfiles statement, using the file's size in the comparison.
open dst=ipaddr user=uid pwd=password forfiles local=c:\sourcedir\afile.txt fileattrib=yes # Make sure we have enough space available diskspace dst=c:\targetdir qty=$(_file.size) cond=GT # We do, copy the file. if $(_lastrc.result) EQ 0 copy local=$(_file) dst=c:\targetdir\$(_file) end end
The statements below repeat the previous example using the $(_diskspace) built-in variable. The if statement only allows the file copy if the number of bytes available on c:
is greater than the size of the input file.
open dst=ipaddr user=uid pwd=password forfiles local=c:\sourcedir\afile.txt fileattrib=yes # Make sure we have enough space available diskspace dst=c:\targetdir # We do, copy the file. if $(_diskspace) GT $(_file.size) copy local=$(_file) dst=c:\targetdir\$(_file) end end
The following example uses diskspace in the context of a forfiles loop, using the total size of several files to determine the quantity of space needed.
set spaceNeeded=0 open dst=ipaddr user=uid pwd=password forfiles local=/home/datadir/*.txt fileattrib=yes set spaceNeeded=<$(spaceNeeded) + $(_file.size)> end # Make sure we have enough space available diskspace dst=c:\targetdir qty=$(spaceNeeded) cond=GT # Only execute the "forfiles" statement if we have enough space # for all the files. if <"$(_lastrc.message)" EQ "SUCCESS"> forfiles local=c:\sourcedir\*.txt copy local=$(file) dst=c:\targetdir\$(_file) end end
The statements below repeat the previous example using the $(_diskspace) built-in variable.
set spaceNeeded=0 open dst=ipaddr user=uid pwd=password forfiles local=/home/datadir/*.txt fileattrib=yes set spaceNeeded=<$(spaceNeeded) + $(_file.size)> end # Make sure we have enough space available diskspace dst=c:\targetdir # Only execute the "forfiles" statement if we have enough space # for all the files. if $(_diskspace) GT $(spaceNeeded) forfiles local=c:\sourcedir\*.txt copy local=$(file) dst=c:\targetdir\$(_file) end end
The following example would prevent a copy if the available space for the volume or file system that contains the specified directory is less than 20MB.
open dst=ipaddr user=uid pwd=password diskspace dst=c:\targetdir qty=20m cond=lt if $(_lastrc.result) EQ 0 echo "Not enough space. Will not copy." else echo "OK to copy" copy local=c:\sourcedir\somefile.txt dst=c:\targetdir\somefile.txt end The statements below repeat the previous example using the $(_diskspace) built-in variable with the {{.mb}} attribute. open dst=ipaddr user=uid pwd=password diskspace dst=c:\targetdir if $(_diskspace.mb) LT 20 echo "Not enough space. Will not copy." else echo "OK to copy" copy local=c:\sourcedir\somefile.txt dst=c:\targetdir\somefile.txt end