Unable to redirect and/or pipe stdout of commands (on AIX)

This post is similiar to Unable to redirect command line output - but that was Windows. AIX (and perhaps Linux) seem to behave differently

I am trying to use the following Action script.

I see I can use appendfile, move, wait to get it done - and shall do that if nothing else can be done.
Maybe I need to ignore my feelings about using double double-quotes (now using single-quotes). Should that be the solution - would request some additional feedback, better examples, in the online reverence for Action wait/run and other related commands.

// Action script and i/o redirection - through pipes?

// command I want to run is: /usr/bin/grep -p default: /etc/security/user | egrep "histsize|min|max|retries" | egrep -v "core|admin" 

wait sh -c '/usr/bin/grep -p default: /etc/security/user | egrep "histsize|min|max|retries" | egrep -v "core|admin" >/tmp/p0'

wait sh -c 'grep -p default: /etc/security/user > /tmp/p1'
wait sh -c 'egrep "histsize|min|max|retries" /tmp/p1 > /tmp/p2'
wait sh -c 'egrep -v "core|admin" /tmp/p2 >/tmp/p3'

delete appendfile
delete "/tmp/p5.sh"
appendfile /usr/bin/grep -p default: /etc/security/user | egrep "histsize|min|max|retries" | egrep -v "core|admin" >/tmp/p5

move __appendfile /tmp/p5.sh
wait sh /tmp/p5.sh

My “results” - only the files /tmp/p5.sh and /tmp/p5

The “action” output shows:

see these
“>” doesnt work in the action script. you have to put that in the file first.

Your mileage may vary, but this is my working test on Red Hat / CentOS:

wait /bin/sh -c "echo {id of action} > '/tmp/file output {id of action}'"

1 Like

Yes, (@JasonWalker - you are coming with a correct example) and maybe it was you in the other thread who commented about is it “sh|cmd.exe” that is seeing the command redirection, or the script/command that sh -c is calling.

In any case, on AIX - you need double quotes on the “outside” and include the file redirection within the quotes, and between these double quotes - use single quotes.

Command succeeded (Exit Code=127) wait sh -c "egrep "histsize|min|max|retries" /tmp/p1 > /tmp/p2" (action:4610)

compared with:

Command succeeded (Exit Code=0) wait sh -c "egrep 'histsize|min|max|retries' /tmp/p1 > /tmp/p2" (action:4613)

1 Like

So…did the second example you posted produce the output file you wanted? Did you solve it?

…the first example you posted isn’t quite the same as mine, either. I had doublequotes on the outside, and single quotes embedded in the command, where you repeated it back with doublequotes in both places. Since you have access to an AIX machine to test with, can you let me know whether that works too?

Yes, here is the working example.

Note: using wait sh -c "some command >redirect" seems to require the sh -c part. If I try something like:

wait "ls /tmp >/tmp/xyz" I do not get the expected results, while wait sh -c " "ls /tmp >/tmp/xyz" is working.

// command I want to run is: /usr/bin/grep -p default: /etc/security/user | egrep "histsize|min|max|retries" | egrep -v "core|admin"

wait sh -c "/usr/bin/grep -p default: /etc/security/user | egrep 'histsize|min|max|retries' | egrep -v 'core|admin' >/tmp/p0"
// indivudual commands also work, but are not required - as pipes are accepted
//    wait sh -c "grep -p default: /etc/security/user > /tmp/p1"
//    wait sh -c "egrep 'histsize|min|max|retries' /tmp/p1 > /tmp/p2"
//    wait sh -c "egrep -v 'core|admin' /tmp/p2 >/tmp/p3"

Ok, great, I think we’re both seeing the same behavior -

  • output redirection is a function of the shell, so we need the sh -c "quoted commands"
  • within the command we can embed single-quotes for things like filenames with spaces or grep’s with embedded pipes

So now, if we can convince powers that be / that this may be a useful addition with examples in the online documentation.

I had another trying time figuring out how to get a second and third “{” character to go to a createfile properly. Have to think about how to write that up properly - I needed an awk file with /selection/ { statements } and END { statements } to create “key”=“value” pairs that an analysis will read.

So, a write up for that will come eventually, I need to work on something else more urgent first.