Operating System - HP-UX
1827811 Members
2120 Online
109969 Solutions
New Discussion

Re: Need help creating a script

 
SOLVED
Go to solution
Shikha Punyani
Advisor

Need help creating a script

Hi All , I want to create a ksh script in HPUnix..
Requirements are :
Client will place file of format XXEGO_PIM_HEADERS_DDMMYYYY.DAT in souce directory let us say A and script need to move it to directory B and once it get moved the format of file should look like ILE512_PIM_EXTRACT1.DAT...I am new to scripting, please help ASAP.

Also I just created a script in which client have placed a file in format FILE500_SITEDB.CSV_YYMMDDHHMM and it should get copy to another direcorty without that time stamp and please see the script below which is working now...however in the above request I am unable to identify how it will serach for this pattern..XXEGO_PIM_HEADERS_DDMMYYYY.DAT ..Please help!
11 REPLIES 11
Jose Mosquera
Honored Contributor
Solution

Re: Need help creating a script

Hi,

I'm not sure I understand your attached script. In any case I hope the new attached script will be useful to you.

Rgds.
Jose Mosquera
Honored Contributor

Re: Need help creating a script

Ooops, my previous post have an error. Please try with this one.
Jose Mosquera
Honored Contributor

Re: Need help creating a script

Wooow, wrong again ... ... this one yes!
Shikha Punyani
Advisor

Re: Need help creating a script

Hi Jose,
First of ALL thanks a ton for your support :)
YOur script is very good ..I tried it on test server and it is working well..
I have also created script yesterday (Please find it attached)which is working fine..however yours is simple and easy...

I have one question..
In one Script, the client will place the file in the format.
File will come in this format : XXEGO_GL_DDMMYYYY.DAT
Source Directory:
/u03/UBIDW/data/backup Destination Directory:
/u03/UBIDW/data/inbound/FILE511_PIM_GL.TXT
Operation: Copy the fiole from source to destination...
When it move in to destination directory its name should be like
FILE511_PIM_GL.TXT
without timestamp...and name changed as well...
Jose Mosquera
Honored Contributor

Re: Need help creating a script

Hi,

The destination filename have a specific creation rule, or just always will be FILE511_PIM_GL.TXT?

Rgds.
Shikha Punyani
Advisor

Re: Need help creating a script

Yes destination Filae name will always be the same...
Also script should only pick up with file containing XXEGO_PIM_HEADERS with Latest time stamp in source directory....
Jose Mosquera
Honored Contributor

Re: Need help creating a script

Maybe this be enough:

SOURCE_DIR=/u03/UBIDW/data/backup
TARGET_DIR=/u03/UBIDW/data/inbound
cd $SOURCE_DIR
FILE_TO_MOVE=`ls -ltr XXEGO_GL_*.DAT|tail -1|awk '{ print $9 }'`
mv ${FILE_TO_MOVE} ${TARGET_DIR}/FILE511_PIM_GL.TXT

Please try and tells me something...

Rgds.
Shikha Punyani
Advisor

Re: Need help creating a script

Will this be picking up t he latest date stamp files?
Let us say if there is a file present in the source dir with previous date stamp and with latest date stamp will it be able to pick the file with latest date time stamp?
Scripts looks good it work well :)
Jose Mosquera
Honored Contributor

Re: Need help creating a script

Hi,

I'm listing files XXEGO_GL_*.DAT with reverse time creation. With this, files are sorted placing the most recient file at end of the list, then "tail -1" always show the last file of the list. Please note that I am evaluating the file creation time on the system.

A possible issue, imagine this situation: you have these four files:
XXEGO_GL_17022011.DAT
XXEGO_GL_18022011.DAT
XXEGO_GL_19022011.DAT
XXEGO_GL_20022011.DAT
At first time the script will move the last file XXEGO_GL_20022011.DAT, but if this script run again the file XXEGO_GL_19022011.DAT will be moved, and so on.
A good control could be set a reference timestamp variable that ensure move only certain files that match date:
SOURCE_DIR=/u03/UBIDW/data/backup
TARGET_DIR=/u03/UBIDW/data/inbound
TODAY=`date +%d%m%Y`
cd $SOURCE_DIR
FILE_TO_MOVE=`ls -ltr XXEGO_GL_${TODAY}.DAT|tail -1|awk '{ print $9 }'`
if [ "$FILE_TO_MOVE" = "" ]
then
echo "Today's file has yet not arrived"
exit 6
fi
mv ${FILE_TO_MOVE} ${TARGET_DIR}/FILE511_PIM_GL.TXT
exit 0

I hope this is useful...


Shikha Punyani
Advisor

Re: Need help creating a script

That is all for today...
I got all my answers
Again Thanks a ton for our support :)

Have a great d ay ahead !
Jose Mosquera
Honored Contributor

Re: Need help creating a script

Shikha,

Glad to assist you, and best regards.