Page 1 of 1

After-job routine calls unix command 'sed'

Posted: Tue Oct 23, 2007 3:44 pm
by ebmusa
Does anyone know why after-job routine ExecSH does not work on unix command like --> sed "s/a/b/g" <input.txt >output.txt ??

This command works fine if I run it on the command line.

Thanks.

Posted: Tue Oct 23, 2007 4:24 pm
by chulett
:? What doesn't work about it? If I had to guess, I'd assume it is because you are using relative file paths...

Posted: Tue Oct 23, 2007 7:37 pm
by ebmusa
The command uses absolute path. The command does not work because there is no output.txt file created, and there is no output from the DSExecute("UNIX",..,output,msg) function to tell what went wrong.

Thanks,

Posted: Tue Oct 23, 2007 8:16 pm
by chulett
Your 'example' shows a relative path, hence the guess. First you mentioned ExecSH and now DSExecute. Please post the exact syntax you are using to execute whatever command you are running.

:idea: DSExecute returns information in the two variables you name at the end of the call - check the docs. For what you posted, 'output' would be the name of a variable that captured anything echoed to standard out by the script/command and 'msg' would be a variable that captures the exit code from the script/command.

And what is ".." for the UNIX command to actually execute supposed to mean? :?

Posted: Wed Oct 24, 2007 7:43 am
by ebmusa
Sorry for not clearly explained my situation.

If you look at the built-in source code for routine ExecSH, it actually calls the DSExecute() function to execute the unix command. the output and msg (or should I say returncode) can be used for capturing what is going on. These two arguments returned nothing in my case.

I guess what I try to ask is if anyone has used the sed command successfully. for instance, I had experience that ExecSH complained the command $(date) but not `date`

Thank you very much for your reply!

Posted: Wed Oct 24, 2007 8:01 am
by chulett
Again, best if you post your actual syntax. There should be no issues calling any operating system command but seeing your syntax and any errors generated would be helpful in figuring out what is going on.

Posted: Wed Oct 24, 2007 9:22 am
by ebmusa
Here is the exact input value for Afater-Job Routine ExecSH I used:

sed "s/a/b/g" < #FilePath#/input.txt > #FilePath#/output.txt
where #FilePath# is /dir1/dir2/dir3

I can see in the job log that the #FilePath# is expanded correctly, but there is nethier error messages nor output.txt file being generated.

Thanks,

Posted: Wed Oct 24, 2007 10:28 am
by lstsaur
I did a sed 's/a/b/g' < /tmp/input.txt > /tmp/output.txt in my job's After-job subroutine and it produces expected results.

Try use single quote and hard-coded the path.

Posted: Wed Oct 24, 2007 10:42 am
by Ronetlds
Call DSExecute("UNIX", sed 's/a/b/g' < /tmp/input.txt > /tmp/output.txt , output, systemreturncode)

Posted: Wed Oct 24, 2007 11:52 am
by ebmusa
yahooooo! It works. Thank you so much :P

Posted: Wed Oct 24, 2007 12:05 pm
by chulett
So, what actually fixed it for you? The switch to single quotes? Were you still able to levelage your file path parameters?

Posted: Wed Oct 24, 2007 12:28 pm
by ebmusa
The single quote solved my problem. Although using both double and single quotes work fine on the unix command line, but I guess DataStage only likes the single quote.

Yes, the file path parameter stays the way as it was.

Thank you all again :P