Page 1 of 2

File nane with date

Posted: Thu Apr 17, 2008 5:38 am
by Kshitij Rawat
Hi All,

I want to add current date in a file name.
For example my file name is user_records.csv
But my client want to add sysdate with this file name
Suppose sysdate is 20080417 the my file name would be "user_records_20080417"

I know with the help of Unix script we can do it ...
But is there any way in DataStage(PX or Server job) so that I can do it without Unix Shell script....

Waiting for your reply.
:)

Posted: Thu Apr 17, 2008 5:40 am
by ray.wurlod
Yes, but it involves writing an after-job subroutine. You may as well use ExecSH as the after-job subroutine to execute a UNIX mv command.

Posted: Thu Apr 17, 2008 6:16 am
by Kshitij Rawat
ray.wurlod wrote:Yes, but it involves writing an after-job subroutine. You may as well use ExecSH as the after-job subroutine to execute a UNIX mv command. ...

Thanks you very much for your help Sir.

Posted: Thu Apr 17, 2008 7:06 pm
by jhmckeever
If your concern with the Unix option is that you don't want another 'asset' to have to manage outside the DataStage environment then couldn't you just supply the 'script' in the filename specification?

E.g. Something like ...

Code: Select all

MyFilename_`date +%Y%m%d-%H%M%S`.txt
I've been working in a purely PX environment for quite some time and don't remember if this will work in server - so apologies in advance if it's not appropriate to your environment.

John.

Posted: Thu Apr 17, 2008 7:24 pm
by ray.wurlod
It's entirely appropriate to server (on UNIX).

Posted: Thu Apr 17, 2008 7:32 pm
by jhmckeever
Jolly good.

Ray - Let me know if you're ever running a "Parallel to Server" transition class! ;-)

John.

Posted: Thu Apr 17, 2008 8:27 pm
by ray.wurlod
Interesting question. I wonder what the demand would be.
:)

Posted: Fri Apr 18, 2008 9:33 am
by ds_developer
You can also append a job parameter to the filename, as in:

user_records_#RUN_DATE#.csv

assuming you can set the #RUN_DATE# parameter. I do this on all my reject files.

John

Posted: Fri Apr 18, 2008 3:51 pm
by ray.wurlod
Moderator: please move to parallel forum

Posted: Wed Apr 23, 2008 7:49 am
by sinhasaurabh014
answered....just repeating..in case you may have 4gotten
use #DSJobStartDate# macro in the filename.
eg. c:\data\target_file_#DSJobStartDate#.txt
only you get date as 2008_04_23 if that is acceptable.

Nice time to ask another question.....
:?: Is there some way we can create or Modify an existing DS Macro?

Re: File nane with date

Posted: Thu May 01, 2008 8:51 pm
by suren_sharma06
Kshitij Rawat wrote:Hi All,

I want to add current date in a file name.
For example my file name is user_records.csv
But my client want to add sysdate with this file name
Suppose sysdate is 20080417 the my file name would be "user_records_20080417"

I know with the help of Unix script we can do it ...
But is there any way in DataStage(PX or Server job) so that I can do it without Unix Shell script....

Waiting for your reply.
:)

Hi all,

Even my client need the file with date as mentioned above, however he needs version number also.

For example, the output file format should be FILENAME_DD_MM_YYYY_XX
where XX is version number.

If due to some reason job is run twice a day, the file should have XX values as 01 for the first time and 02 for the second time.

Even the client is specific for date format too.

Please help !!

Posted: Thu May 01, 2008 10:13 pm
by jhmckeever
Using the 'script' approach I outlined previously you can specify your own date format. E.g. DD_MM_YYYY would be ...

Code: Select all

MyFilename_`date +%d_%m_%Y`.csv
What are the criteria for incrementing the version number? Every job run? If so, you could store the value in an environment variable and use a before-Job ExecSH to increment it ...

Code: Select all

MYVAL=`expr $MYVAL + 1`
Then refer to that environment variable in your filename specification:

Code: Select all

MyFilename_`date +%d_%m_%Y_$MYVAL`
There are other approaches which I'm sure other posters will provide if needed.

John.

Posted: Thu May 01, 2008 11:32 pm
by suren_sharma06
jhmckeever wrote:Using the 'script' approach I outlined previously you can specify your own date format. E.g. DD_MM_YYYY would be ...

Code: Select all

MyFilename_`date +%d_%m_%Y`.csv
What are the criteria for incrementing the version number? Every job run? If so, you could store the value in an environment variable and use a before-Job ExecSH to increment it ...

Code: Select all

MYVAL=`expr $MYVAL + 1`
Then refer to that environment variable in your filename specification:

Code: Select all

MyFilename_`date +%d_%m_%Y_$MYVAL`
There are other approaches which I'm sure other posters will provide if needed.

John.
The job is schedule to run everyday. So idealy there will be only one version per day. But if due to some reason, you run the job twice a day, then it should create second version.

For the next day. version should be set back to 01 again.

I appriciate above solution, but it would be great if somebody tells me solution without script.

Posted: Fri May 02, 2008 12:09 am
by jhmckeever
It might help if you told us why you don't / won't / can't use a shell-based solution.

An alternative is to construct a DSBasic routine:
- Use the system date to construct a filename mask (E.g. MyFile_DD_MM_YYYY_*)
- Take a look at the relevant directory to see if any of today's files exist yet (sort the output)
- Get the highest sequence number from today's files (if any)
- Generate the appropriate filename as your routine's return value (using highest sequence number + 1)
- Call this routine from a job sequence using a User Variables activity
- Reference the routine's variable as an input parameter to the job creating the file.

Actually you could get the latest of today's files with a combination of ls -1, sort, and head commands.

Hope your reason for avoiding the shell solution is good enough to justify all the extra effort! :-)

John.

Posted: Fri May 02, 2008 12:12 am
by Rubu
ray.wurlod wrote:It's entirely appropriate to server (on UNIX).
Hi Ray,

Is this because the file name is going as a part of argument to export operator in PX?

Then, just wondering whether Server uses something like touch <file_name> for creating the target file?