cancel
Showing results for 
Search instead for 
Did you mean: 

Unix script for picking file from R/3 Application server

former_member190358
Participant
0 Kudos

Hello Everyone,

I have a requirement to pick up the actual file, based on the trigger file from R/3 Application server directory and then move it to 3rd party FTP server.

1) So basically its a File to File scenario .

2) The input file called ABC.OK is a trigger file based on which  i have to pick up the actual file ABC .

3) This solution, i am planning to adopt by using UNIX script.

4) Please let me know, how do i proceed and what should be logic to check  functionality.

Regards,

Ravi

Accepted Solutions (1)

Accepted Solutions (1)

anupam_ghosh2
Active Contributor
0 Kudos

Hi Ravi,

              Did you check my response in this thread? I feel it is the same requirement.

http://scn.sap.com/thread/3190285.

Regards

Anupam

former_member190358
Participant
0 Kudos

Hello Anupam,

Yes, its the same  requirement. Since we have tried a lot with Adapter module, so now we are trying with script.

However, could you please help me with the complete  script and let me know how to use it in sender file adapter ..

Ravi

anupam_ghosh2
Active Contributor
0 Kudos

Hi Ravi,

               I think I wrote the complete script. You can remove the sleep statement and test in UNIX enviornment. Let me know if you need more information.

Regards

Anupam

former_member190358
Participant
0 Kudos

Hello Anupam,

This time i just want to delete the file . the code is as follows .

However  i am getting the error as " Error executing OS command ".

logDir=/interface/tes/archive

logFile=deleteMATMASTFiles.log

currDate=`date`

a="ABC.OK"

echo "$currDate - SUCCESS-Source File Name $a" >> $logDir/$logFile

rm $a

echo "$currDate - SUCCESS-File is deleted" >> $logDir/$logFile

Former Member
0 Kudos

Hi Ravi,

I still don't understand the approach but your could try something like this:

#!/bin/sh (this would vary according the the Unix flavour and shell you're running - Google <sh, bash, ksh etc.> or speak to Basis regarding correct approach for you)


# Find the file you're looking for and remove at the same time
find . -type f -name "ABC.OK" -exec rm -f {} \;


# Test return code - if command was successful - i.e. Was the file found? Then (>>) Append the output to a logfile
if [ $? -eq 0 ];then
  echo "`date` - SUCCESS - Source file found and removed" >> /interface/tes/archive/deletMATMASTFiles.log   
else
  echo "`date` - FAILED - No Source file found" >> /interface/tes/archive/deletMATMASTFiles.log   
fi

Also, ensure that your script is executable, researh Unix chmod command.

Regards, Trevor

former_member190358
Participant
0 Kudos

Hello Anupam,

I tried deleting the file of R/3 application server by this script. But the  log gets created , however the file does not get deleted ....  I tried everything but not able to understand what to do now ??

logDir=/interface/scripts

logFile=deleteMATMASTFiles.log

echo "Entered script" >> $logDir/$logFile

host="137.40.169.226"

open ${host}

cd /interface/tes

currDate=`date`

chmod +x makt_EN_material_descr

delete makt_EN_material_descr

Former Member
0 Kudos

Hi Ravi,

I don't think it will work like that, maybe try something along these lines:

logDir=/interface/scripts
logFile=deleteMATMASTFiles.log
echo "Entered script" >> $logDir/$logFile
USER=userid
PASSWD=userpwd
HOST="137.40.169.226"

ftp -n $HOST <<END_OF_FTP >> /interface/scripts/ftp_connection.log
user $USER $PASSWD
cd /interface/tes
binary
prompt off
delete makt_EN_material_descr
quit
END_OF_FTP

echo "Leaving script" >> $logDir/$logFile

Regards, Trevor

former_member190358
Participant
0 Kudos

Hello Trevor,

Your code clicked.. i think my script was not able to call the host .. that's the reason why, the connection was not happening remotely.

However, there is a small twist here, that i have to now modify the logic in such a way that i cannot hardcode the name of the file in the script.

If my file name is " ABC.ok"  in the channel, then i read the first three letters of the file name at run time and then pass the name to delete it from the folder "/interface/tes".

Could you pls help me if this possible in script .

Regards,

Ravi

Former Member
0 Kudos

Hi Ravi,

You want to remove the file extension? If that's the case, you could probably pass the actual file name (ABC.ok) as a parameter to the script. So when you call the script (i.e. Run OS command) after the script name add %f (this would pass through the filename as the 1st parameter to the script as $1) so you would set the filename dynamically at runtime, see SAP Help:

http://help.sap.com/saphelp_nw04/helpdata/en/bc/bb79d6061007419a081e58cbeaaf28/content.htm

See "Run Operating System Command" section

Once you have the filename in the script you can then manipulate the name as desired. You could ass the following command in the script before you initiate the ftp call, example:

newname=${1%\.*}

Then when issuing the delete command it would be:

delete $newname

Also Google the use of the 'basename' command in Unix, that could also be used.

Regards, Trevor

former_member190358
Participant
0 Kudos

Hello Trevor,

I have a new scenario where, the  trigger file name is *.LOG  and actual file is *.DAT.

I have to delete the .DAT file from R/3 Application server and i have written a script for it.

But the file is not getting deleted from the folder:

logDir=/interface/scripts

logFile=deleteMATMASTFiles.log

echo "Entered script" >> $logDir/$logFile

USER=***

PASSWD=***

HOST="***"

newname=${1%\.DAT}

ftp -n $HOST <<END_OF_FTP >> /interface/scripts/ftp_connection.log

user $USER $PASSWD

cd /interface/tes

binary

prompt off

delete $newname

quit

END_OF_FTP

Regards,

Ravi

Answers (2)

Answers (2)

rajasekhar_reddy14
Active Contributor
0 Kudos

Hi Ravi,

Try below approach

1)Craete sender channel and enter source directory and file name should be  ABC.OK and Processing mode Delete.

2)Create script to tranfer file from App server to FTP , and no need to write any logic here to like check weather file ABC.OK exist or NOT.

3)Use option in File adapter like RUN OS commands after message processing.

Search in SCN and google ti to get sample code to tranfer file from one FTP to other FTP.

Regards,

Raj

former_member184681
Active Contributor
0 Kudos

Hi Ravi,

Check Question#4 of my Wiki below:

Sender File Adapter Frequently Asked Questions

It describes an example approach on how to work with trigger files.

Regards,

Greg

former_member190358
Participant
0 Kudos

Hello Greg,

Unfortunately we cannot use NFS and we are using FTP as our protocol.

Could you suggest similar option in case  of FTP protocol.

Ravi

former_member184681
Active Contributor
0 Kudos

Dear Ravi,

Well, for this requirement in FTP, I would still go for an adapter module. It shouldn't be too difficult to develop, if you search for "adapter module FTP", you will find a few helpful threads in our area. With a shell script, your requirement would get complicated, since PI processes the message further no matter what is the result of the shell script (you cannot prevent the message from being processed, using shell script).

Regards,

Greg

baskar_gopalakrishnan2
Active Contributor
0 Kudos

Remember your previous thread. DId you change your mind from adapter module to unix? I already suggested to go for unix script. Take help from Unix team or BASIS.  You might have to do few lines of coding for this.

Example: to find the specified file you have to use find command

find / -name  -ABC

Where /  - root directory or you can specify the directory path

name  - name of the file.

former_member190358
Participant
0 Kudos

Hi Baskar,

Finally, i have decided to do the entire process by adapter module and the problem of deleting the file will be done by script ( RUN OS commands after message processing)

i hope this should be fine and not give me any problem in execution.

Now trying to know how can i achieve the last step..as i have not done it yet.

Regards,
Ravi

Former Member
0 Kudos

Hi Ravi,

I'm just wondering why you can't just pass the data straight through to PI from the R/3 Application server?

Personally I feel that the OS script option should ONLY be used in cases where data integrity isn't an issue and not in cases where there are huge dependencies on the script being executed successfully OR you have an effective way of monitoring & managing script execution failures.

The reason I'm saying this is that OS scripts work largely with return codes that PI seems to blatantly ignore after you run an OS Command from PI. I've seen cases where a directory structure wasn't mounted on the receiver end and the script was executed (unsuccessfully) but PI was none the wiser and you could see green lights all around in PI. The only other way to check it is to write the standard output from the script to a logfile to investigate reactively (after someone reports an issue). I think using scripts is a bit of a black hole in terms of monitoring. I would follow Greg's adapter module suggestion or find an alternative way of getting the data from R/3.

Regards, Trevor

former_member190358
Participant
0 Kudos

Hello Greg,

For sometime  i have been struggling to achieve the solution to this problem,  however, now  i have taken a  midway.

I am doing my entire process through adapter module and the process of deleting the file, which  was giving me problem , will be done by batch commands now.

I tried it, but i am getting an error as " Error Executing OS command "

Can you help me here

Ravi

former_member190358
Participant
0 Kudos

Hello Trevor,

I have a trigger file logic and so i created a adapter module , however the module was giving me some problem while deleting the file. so i plan to  adopt the entire module for my other process and  now the script will be used to delete the file.

However , now after all this, i am getting an error as " Error in Executing OS command " .

Regards,
Ravi

former_member184681
Active Contributor
0 Kudos

Dear Ravi,

I believe there is one crucial thing that you have to bear in mind:

"Note that for the File Adapter transport protocol "FTP", the operating system command is NOT executed on the FTP server, but on the server hosting the Adapter Engine."

For details, see SAP Note 841704 - XI File & JDBC Adapter: Operating system command.

I believe that since you are processing the file with an Adapter Module, it could be the best idea to also delete the file there, instead of dividing the logic to Adapter Module and OS Command.

Regards,

Greg

baskar_gopalakrishnan2
Active Contributor
0 Kudos

>, however the module was giving me some problem while deleting the file

What prevents you to delete the file in the module logic itself. Since you have gone for almost everything via module development, why don't do the delete file there. What third party tool that stop doing this?  

Just Example:

refer this example for delete operation.

http://www.roseindia.net/java/beginners/DeleteFile.shtml