One Star

Not able to run Linux command using tSystem Component

Hello All,
I am running following command in TOS using tSystem Component. But It is not performing the task rather displaying the contents in the console when its executable is run.
sed 's/_DEV/_PROD/' input_file > output_file
I am passing input_file and output_file from context params.
Please help.
11 REPLIES
Seventeen Stars

Re: Not able to run Linux command using tSystem Component

try this:
sed 's/_DEV/_PROD/' " + context.input_file + " > " + context.output_file

Re: Not able to run Linux command using tSystem Component

I think the issue is because you are using redirection (">") in the command. Try using the below Java code in the command box:
new String[]{"/bin/bash","-c","sed 's/_DEV/_PROD/' input_file > output_file"}

Click here for more details on the same
Four Stars RSH
Four Stars

Re: Not able to run Linux command using tSystem Component

Hello Vikram,
I want to add custom headers (only 1 line) in all my target txt files. I am using windows remote connection in that I use talend 5.6 linux box. I use following code but unable to add custom headers.
Code in tsystem(Use line Command)-
new String[]{"/bin/bash tempath='/home/UserName/Desktop/CI0.txt' Filepath='/home/UserName/Desktop/HeaderCi.csv'  for line in $temppath; do cat $Filepath $line>tmp && mv tmp $line done"}
Error-
Exception in component tSystem_1
java.io.IOException: Cannot run program "/bin/bash tempath='/home/UserName/Desktop/CI0.txt' Filepath='/home/UserName/Desktop/HeaderCi.csv'  for line in $temppath; do cat $Filepath $line>tmp && mv tmp $line done" (in directory "/home/UserName/Desktop/CI"): error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1042)
Note:
If I tick mark or not tick mark "Use Home directory"  , in both condition I get same error.
I use following command too but not working:
"sed -i '1s/^/'Custome_Header_Name'\n/' CI*.txt"
"echo 'Custome_Header_Name' | cat - CI0.txt > temp && mv temp CI0.txt"
echo "$(echo 'Custome_Header_Name' | cat - CI0.txt)" > CI0.txt

Please guide me.
Four Stars RSH
Four Stars

Re: Not able to run Linux command using tSystem Component

Dear All,
Can anyone please guide me for same , as I am unable to resolve this problem.
Regards
Rsh
Four Stars RSH
Four Stars

Re: Not able to run Linux command using tSystem Component

Dear Team,
Please help me out as I am running out of time..
Regards
RSH
Community Manager

Re: Not able to run Linux command using tSystem Component

Hi RSH
Could you try to run this command in Linux prompt to see it works before you use tSystem?
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
Four Stars RSH
Four Stars

Re: Not able to run Linux command using tSystem Component

Hello Shong,
Thanks a lot for your reply.
Your suggestion to check in Linux prompt, Can you please tell me how to do it? This is first time I am using remote->linux box-> talend(5.6) hence not sure how to use Linux.
Shong , can you please suggest steps to check it.
If you are talking about to check my code using CMD(PUTTY), then YES, my code works and I get my expected result in all my 100+ files.
Shong sir, can you please check my code in your environment if possible, because since last week I am working on same thing and not getting any result.
Please guide.
Regards
RSH
Community Manager

Re: Not able to run Linux command using tSystem Component

Hi RSH
Yes, I meant to run this command in Linux CMD to make sure there is no syntax error in the command. Can you please upload a screenshot to show how your command works in Linux CMD.
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
Four Stars RSH
Four Stars

Re: Not able to run Linux command using tSystem Component

I have 3 files in my drive i.e.
1. text file in which we get target output data from oracle source. File name is CI0.txt
2. Headerfile in which we have header format which is useful for froent end team (to load file in front end).File name is HeaderCI.csv
3. Script which has code to add header file data in target CI0.txt file. 
Now I have to run script from Putty. (Screen shot in attachment.)

Even if we try normal single command like:sed -i '1s/^/'Custome_Header_Name'\n/' CI*.txt
This code works in putty but not working in Talend.

Talend Job Snapshot:
I am using same directory, same path, but normally It gives me an error "NO SUCH FILE DIRECTORY" or syntax error even though it shows me OK status.

Sir, can you please let me know where I made an error.
Regards
RSH
Seventeen Stars

Re: Not able to run Linux command using tSystem Component

hi all,
try to wrap your sed command in a .sh file to avoid problem with special character & quotes.
hope it help
regards
laurent
Four Stars RSH
Four Stars

Re: Not able to run Linux command using tSystem Component

Bonjour Laurent,
Thank you for reply. Yes, It works if I create an .sh file which contains sed -i '1s/^/'Custome_Header_Name'\n/' CI*.txt
code, but my problem is after I migrate source data from oracle to txt file(split after 1000 records), this target txt folders gets deleted prior to new file creation on daily basis, so in this case my .sh script file will get deleted and to add custom header I need to create it again .sh file in particular folders.
Conclusion: I need to pass header file path(Custome_HEader_Name) and folder name(target folders employee, students etc) path in which I have to add header.Henceforth I used following code:
"/bin/bash tempath='/home/UserName/Desktop/CI0.txt' Filepath='/home/UserName/Desktop/HeaderCi.csv'  for line in $temppath; do cat $Filepath $line>tmp && mv tmp $line done"
Please let me know in case you have some other work around.
Thanks Again.
RSH