1

I tried to get command output in a command but I could't get it. If I run manually, It return normal result in screen.

[root@mymachine ~]# dnsdist -e "topQueries()" 1 Rest 0 100.0%

I tried with dnsdist -e 'topQueries() 2>&1 1> /tmp/abc. But /tmp/abc still was empty. I don't think screen command can resolve it. Does anyone have any recommendations?

Addition information:

1 Rest 0 100.0%

is the result from topQueries(). '-e' mean execute a command in dnsdist. It works look like we access mysql then we call a sql statement.

13
  • and result is printed on screen ? Commented Dec 4, 2016 at 15:11
  • Yes. As my example, After I run command manually, I see this result in screen. Commented Dec 4, 2016 at 15:13
  • Order of redirection is important, how about examplecommand > /tmp/abc 2>&1 Commented Dec 4, 2016 at 15:17
  • If you want it, i will send. This command come from dnsdist rpm (version 1.1 beta). Command: dnsdist -e 'makeKey()' Commented Dec 4, 2016 at 15:18
  • I tried with your way, both /tmp/abc and screen are empty. Commented Dec 4, 2016 at 15:26

2 Answers 2

1

As rkosegi commented, order is important. When you run:

examplecommand 2>&1 1> /tmp/abc

It takes the stderr output and sends it to where stdout is currently going and then sends stdout to the file.

You may want, instead:

examplecommand 1> /tmp/abc 2>&1

which sends stdout to the file, then sends stderr to where stdout is currently going, namely the file.

Sign up to request clarification or add additional context in comments.

3 Comments

It's not work :( Both /tmp/abc and screen still empty value.
Seem I could not get this result from both stdout and stderr
You just missed a > there.
0

To have stderr and stdout both to te screen and in a file /tmp/abc you can use tee.

$cat a.sh
echo "stderr" >&2
echo "stdout"

./a.sh 2>&1 | tee /tmp/abc
stderr
stdout

$ cat /tmp/abc
stderr
stdout

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.