on 10-05-2009 12:41 PM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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
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
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
can you try
rm -r /path/Message_*.tmp
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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]
.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
91 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.