cancel
Showing results for 
Search instead for 
Did you mean: 

Issue with OS Command to handle multiple files in File Adapter

Former Member
0 Kudos

Hi,

A separate process creates a couple of files on PI file system (say Message_1.tmp, Message_2.tmp and so on).

In my scenario, I when I create a target file using receiver file adapter, these tmp files should be renamed to .xml or be deleted. I am using two separate file adapters for renaming and deletion.

In either case, if I use wildcards like *, it does not work.

i.e. the following OS command

rm /path/Message_1.tmp

deletes the file Message_1.tmp

but the command

rm /path/Message_*.tmp

does not work. I need a command that can delete all .tmp file starting with "Message_".

Same issue is with renaming files.

mv /path/Message_1.tmp /path/Message_1.xml

works but

mv /path/Message_*.tmp /path/Message_*.xml

does not work.

Any help is highly appreciated.

Thanks.

Regards,

Riyaz

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

Hi, Riyaz

OS command mv /path/Message_.tmp /path/Message_.xml can't rename multiple files. You must create a script and using it in your communication channel.

However rm /path/Message_1.tmp it's correct. Perharps you need to put full path...

Regards, Carme

Former Member
0 Kudos

Carme,

I tried putting the code in a shell script but it shows error in communcation channel log in RWB (Error in executing OS command "...". No specific error description is shown).

In the OS command option in channel, I put:

/path/delete.sh Message_*.tmp

while in the delete.sh file following snippet:

#!/bin/bash

for i in $1
do
j=`echo $i | sed 's/tmp/xml/g'`
mv "$i" "$j"
done

No idea if this code is correct as I understand very little of unix. I have picked it up from the net. Should the first line say bash, ksh or simply sh?

Kubra,

There could be more than 10 files at a time so option of 0-9 may not work. So I tried using *. I havent tried this option though.

Shabarish,

I tried with -r as well as -f option, however it does not work for multiple files.

Appreciate your inputs.

Regards,

Riyaz

0 Kudos

Hi, Riyaz,

I think your script is not correct.

Try with:

for i in `ls $1`

do

j=`echo $i | sed 's/tmp/xml/g'`

echo $j

mv $1/$i $1/$j

done

In $1 parameter you must specify the full path of your files (without pattern). For example:

sh /path_script/subpath_script/your_script.sh /path_file/subpath_file

Regards,

Carme

0 Kudos

Riyaz

I think you must filter XML file in the script i proposed you. So, change my last code for this one:

for i in `ls $1/*.xml`

do

j=`echo $i | sed 's/tmp/xml/g'`

mv $1/$i $1/$j

done

To delete TMP file, i think you can create a similar script:

for i in `ls $1/*.tmp`

do

rm $i

done

And also In $1 parameter you must specify the full path of your files (without pattern). For example:

sh /path_script/subpath_script/your_script.sh /path_file/subpath_file

Regards,

Carme

Former Member
0 Kudos

Carme,

I tried both the scripts. It doesnt seem to work however.

I put following code in script.sh

#!/bin/sh

for i in `ls $1/*.tmp`
do
j=`echo $i | sed 's/tmp/xml/g'`
mv $1/$i $1/$j
done

and in the OS command in adapter I put:

sh /usr/sap/data1/test/script.sh /usr/sap/data1/test

Tried similarly for delete script.

Now audit log does not show any error/warnings but the files are not renamed/deleted.

What I also observed was, even if I remove the script file from PI server, audit log does not show any errors. Does this mean that I am making any mistake in the OS command I put in the adapter?

Regards,

Riyaz

Edited by: Riyaz Sayyad on Oct 7, 2009 8:24 AM

0 Kudos

Hi Riyaz

i've tested this scripts and they work in my system.

Please, verify:

  • Permissions to delete tmp and xml .

  • Permissions to execute script

  • Try to execute script sh /usr/sap/data1/test/script.sh /usr/sap/data1/test in your PI system directly.

Regards,

Carme.

Answers (2)

Answers (2)

Shabarish_Nair
Active Contributor
0 Kudos

can you try

rm -r /path/Message_*.tmp

Former Member
0 Kudos

to deletes use


rm /path/Message_[0-9]\.tmp

"\." (backslash then dot with no space)

No backslash before the dot would mean just any single character

above command

removes any files starting with "Message" and then any 1 number(extension is .tmp).

u can also use ?(-means any character) instead of

[0-9]

.