Operating System - OpenVMS
1753868 Members
7255 Online
108809 Solutions
New Discussion юеВ

Writing DCL script to sftp the recent created file from the directory

 
Sumant M Kumar
Frequent Advisor

Writing DCL script to sftp the recent created file from the directory

Hi,

I want to write one dcl script which can fetch the latest/recent file from the directory and sftp the file to other windows system.The file format is as below

HPSEC_node.txt_101009;1

The script should search recent file in the existing directory.

Regards,
Sumant
7 REPLIES 7
Steven Schweda
Honored Contributor

Re: Writing DCL script to sftp the recent created file from the directory

> I want to write one dcl script which [...]

You have my permission. Is something (else)
stopping you?

write sys$output f$getsyi( "version"), f$getsyi( "arch_name")
John Gillings
Honored Contributor

Re: Writing DCL script to sftp the recent created file from the directory

Sumant,

Use F$SEARCH to find files, then F$FILE_ATTRIBUTES to determine file dates (you don't specify which date you're interested in, created, modified, accessed, etc...). Use F$CVTIME to convert a date/time into a format that can be compared.

On the other hand, perhaps the filespec you've posted means there's a date stamp embedded into the file extension? (never heard of Y2K?) You can extract that string using F$PARSE and string subtraction:

$ date=F$PARSE(file,,,"TYPE")-".txt_"-".TXT_"

Is that ddmmyy or mmddyy? Realise that neither of those formats can be compared using a normal string comparison, so you'll need to normalise them into yymmdd. Use F$EXTRACT to pull pieces of string. Assuming ddmmyy:

$ date=F$EXTRACT(4,2,date)+ F$EXTRACT(2,2,date)+ F$EXTRACT(0,2,date)
A crucible of informative mistakes
Sumant M Kumar
Frequent Advisor

Re: Writing DCL script to sftp the recent created file from the directory

Thank for your suggestions and help but i am still not able to get the recent file from the existing directory.

Dir name
dka0:[tmp]hp_node.txt_date;1
Each day system creates the file so i need to extract the recent file to do sftp to another node.I am not very good in writing dcl scripts hence i need your help.

Regards,
Sumant
Thomas Ritter
Respected Contributor

Re: Writing DCL script to sftp the recent created file from the directory

Most recent file using ;0

dka0:[tmp]hp_node.txt_date;0

Steven Schweda
Honored Contributor

Re: Writing DCL script to sftp the recent created file from the directory

> I am not very good in writing dcl scripts
> hence i need your help.

For money you can hire someone who is better,
but you would probably need to give him a
clearer explanation of what you wish to do.

> Use F$SEARCH to find files, [...]

That's probably the way I'd try. Have you
tried anything, or are you waiting for
someone else to do your job for you?
The Brit
Honored Contributor

Re: Writing DCL script to sftp the recent created file from the directory

Sumant,
Welcome to the Forum. If you are not familiar with DCL (or OpenVMS) then you probably would benefit from professional help. However, looking at your post, you really are facing two problems.

1. Identifying the file to transfer,
and 2. Doing the transfer from within your script.

In order to solve the identification problem , we need certain pieces of information. For example,

1. is there only going to be one (1) file created each day?
2. will the file ALWAYS be created daily and will this be at a specific time"
3. alternatively, will there be multiple files created daily, of which you only want the most recent? (You know that OpenVMS creates multiple versions of files (?))

The solution to the sftp part of the problem will depend on the TCPIP stack you are using.
------------------------
If there is only going to be one file created each day, then you know what name the file will have, so construct the filename and then look for it. i.e.
(and I assume that "node" needs to be replaced by system nodename)

$ Node = f$getsyi("Nodename")
$ Year = f$extr(2,2,f$cvtime(f$time(),"ABSOLUTE","YEAR"))
$ Month = f$cvtime(f$time(), "COMPARISON","MONTH")
$ Day = f$extr(2,2,f$cvtime(f$time(),"ABSOLUTE","DAY")
$ Date = "''Month'''Day'''Year'"
$ FileName = "HPSEC_''Node'.txt_''Date'"
$ show symb filename
FILENAME = "HPSEC_BUD.txt_101509" (in my case)

to get the "full path spec" of the most recent version,

$ FileName = f$search(FileName,)
$ show symb filename
FILENAME = "USERROOT:[SYSDAB.EON]HPSEC_BUD.TXT_101509;3" (in my case)

If you can get your script to this point, then you are close to the second problem which is the "sftp" step.

get back to us then.

HTH

Dave.

Sumant M Kumar
Frequent Advisor

Re: Writing DCL script to sftp the recent created file from the directory

Hi All,

Thanks for your all assistance ,just to inform you that with help of my one team member created below script.Its doing his job.

We created 2 dcl scripts for get-sftp & put-sftp

$ set noon
$ tod=f$cvtime("",,"weekday")
$ today=f$edit(tod,"UPCASE")
$ IF TODAY .EQS. "SUNDAY" THEN GOTO RESUBMIT
$ SET DEF CDB_DAT
$ sftp "-B" get-bb.com user-id@ip address
$ sho sym $status
$ RESUBMIT:
$SUBMIT/KEEP/USER=system/AFTER="TOMORROW+19:50" SYS$LOGIN:sftp-get-ib
$ PURGE SYS$LOGIN:SFTP-GET-ib.LOG/KEEP=31
$ EXIT

Regards,
Sumant