Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to find whether a file exists on USS

611 views
Skip to first unread message

Mishra, Debnath

unread,
Mar 25, 2004, 4:16:32 PM3/25/04
to
How can we find the existence of a file on USS using rexx(running on z/os)?

Our basic goal in the rexx routine is to do some processing based on whether the file exists on USS or not.

SYSDSN does not understand /usr/lpp/.... as valid.

Thanks
Debnath Mishra
Change Control
Englewood Cliffs, NJ

----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to LIST...@VM.MARIST.EDU with the message: INFO TSO-REXX

Robert Zenuk

unread,
Mar 25, 2004, 5:08:44 PM3/25/04
to
In a message dated 3/25/2004 2:40:20 PM US Mountain Standard Time,

debnath...@CITIGROUP.COM writes:
How can we find the existence of a file on USS using rexx(running on z/os)?

Our basic goal in the rexx routine is to do some processing based on whether
the file exists on USS or not.

SYSDSN does not understand /usr/lpp/.... as valid.

That's because SYSDSN checks the MVS catalog. Nothing in USS is in the
catalog. One way to do this is with USS stat API calls.

Here is a quick and dirty SYSHFS (pardon the name)

Use it the same way you use SYSDSN

/* rexx */
parse arg path
if syshfs(path) <> 0 then
say 'File' path 'not found'
else
say 'File' path 'exists'

Here is the SYSHFS routine:

/*********************************************************************/
/* REXX */
/*********************************************************************/
/* Purpose: Do an existence check on an HFS file */
/*-------------------------------------------------------------------*/
/* Syntax: x = syshfs(path) */
/*-------------------------------------------------------------------*/
/* Parms: path - Fully qualified path to the file */
/* */
/*********************************************************************/
/* Change Log */
/* */
/* Author Date Reason */
/* -------- --------- ----------------------------------------- */
/* R. Zenuk Mar 2004 Initial Creation */
/* */
/*********************************************************************/
parse arg path
/*********************************************************************/
/* Dub the address space */
/*********************************************************************/
if syscalls('ON') <> 0 then
do
say 'Error dubbing SYSHFS RC=99'
exit 99
end
/*********************************************************************/
/* Use USS stat function */
/*********************************************************************/
exit ussapi('stat' path 'stat.')
/*********************************************************************/
/* USS API subroutine */
/*********************************************************************/
ussapi: parse arg usscmd
address SYSCALL usscmd
if RETVAL <> 0 | ERRNO <> 0 | ERRNOJR <> 0 then
do
address SYSCALL 'strerror' ERRNO ERRNOJR 'err.'
say err.SE_ERRNO
parse var err.SE_REASON . '15'x errmsg
say errmsg
say err.SE_ACTION
end
return RETVAL


Hope This Helps,

Rob

Jeff Byrum

unread,
Mar 25, 2004, 5:18:21 PM3/25/04
to
Try this:

/*------------------------------------------------------------------*/
/* Establish SYSCALLS env (REXX/USS Interface) */
/*------------------------------------------------------------------*/
SYSCRC = syscalls('ON')
if SYSRC > 3 then Do
say 'Unable to establish the SYSCALL environment'
return
end
Address SYSCALL

/*------------------------------------------------------------------*/
/* readdir: read directory */
/*------------------------------------------------------------------*/
mydir = '/usr/lpp/...' /* (valid directory name here) */
"readdir" mydir "DIR. FST."

After this, the DIR. compound variable will contain an entry for each file in the directory.

There may be a more direct way to do this than looping throught DIR. compound variable.

If you have QuickRef, you can read about this interface under IBM product "Z/OS UNIX CALLBL SVS" (V1R3) or "Z/OS REX/UNX SYSSERV" (V1R4).

HTH,
Jeff

> -----Original Message-----
> From: TSO REXX Discussion List
> [mailto:TSO-...@VM.MARIST.EDU]On Behalf
> Of Mishra, Debnath
> Sent: Thursday, March 25, 2004 3:58 PM
> To: TSO-...@VM.MARIST.EDU
> Subject: How to find whether a file exists on USS
>
>
> How can we find the existence of a file on USS using
> rexx(running on z/os)?
>
> Our basic goal in the rexx routine is to do some processing
> based on whether the file exists on USS or not.
>
> SYSDSN does not understand /usr/lpp/.... as valid.
>

> Thanks
> Debnath Mishra
> Change Control
> Englewood Cliffs, NJ
>

Robert Zenuk

unread,
Mar 26, 2004, 2:12:41 AM3/26/04
to
I thought about this a little more. If you want a SYSDSN-like tool, it
should give back some text values like SYSDSN does. So here is another version of
SYSHFS with a couple examples of how to use it.

/* rexx - HFSEXIST using SYSHFS */
parse arg path
say path 'is a' syshfs(path)

===> hfsexist /etc/services

/etc/services is a FILE
***

===> hfsexist /u

/u is a DIRECTORY
***

/* rexx - HFSTEST */
parse arg path
if syshfs(path) = 'FILE' then
say path 'exists'
else
say path 'is invalid'

SYSHFS

/*********************************************************************/
/* REXX */
/*********************************************************************/
/* Purpose: Do an existence check on an HFS file */
/*-------------------------------------------------------------------*/
/* Syntax: x = syshfs(path) */
/*-------------------------------------------------------------------*/
/* Parms: path - Fully qualified path to the file */
/* */

/* Notes: Returns the following TEXT strings: */
/* */
/* NOT FOUND if the file does not exist */
/* FILE if the path is found and is a file */
/* DIRECTORY if the path is found and is a directory */
/* SYMLINK if the path is found and is a symbolic link */
/* CHAR if the path is found and is a character file */
/* PIPE if the path is found and is a FIFO file (pipe) */


/* */
/*********************************************************************/
/* Change Log */
/* */
/* Author Date Reason */
/* -------- --------- ----------------------------------------- */
/* R. Zenuk Mar 2004 Initial Creation */
/* */
/*********************************************************************/
parse arg path
/*********************************************************************/
/* Dub the address space */
/*********************************************************************/
if syscalls('ON') <> 0 then
do
say 'Error dubbing SYSHFS RC=99'
exit 99
end
/*********************************************************************/
/* Use USS stat function */
/*********************************************************************/

address SYSCALL 'stat' path 'stat.'
/*********************************************************************/
/* Error processing */
/*********************************************************************/


if RETVAL <> 0 | ERRNO <> 0 | ERRNOJR <> 0 then
do

/*********************************************************************/
/* Translate the cryptic USS errors to cryptic English descriptions */
/*********************************************************************/
say path


address SYSCALL 'strerror' ERRNO ERRNOJR 'err.'
say err.SE_ERRNO
parse var err.SE_REASON . '15'x errmsg
say errmsg
say err.SE_ACTION

return 'NOT FOUND'
end
/*********************************************************************/
/* Return the valid conditions */
/*********************************************************************/
select
when stat.ST_TYPE = S_ISREG then return 'FILE'
when stat.ST_TYPE = S_ISDIR then return 'DIRECTORY'
when stat.ST_TYPE = S_ISSYM then return 'SYMLINK'
when stat.ST_TYPE = S_ISCHR then return 'CHAR'
when stat.ST_TYPE = S_ISFIFO then return 'PIPE'
otherwise return 'INVALID'
end


Hope This Helps,

Rob

0 new messages