user2306856
user2306856

Reputation: 81

stderr not getting redirected to a file in Solaris shellscript

I have written a shell script (on Solaris platform, if that matters), and want to redirect all the output and error of a ZFS command to a file. But when I execute the shell script, the error message is still shown on the prompt instead of redirecting to a file. Following is the shell script:

#!/usr/bin/sh        

`zfs <command>` 2>&1 | tee file.txt   #doesn't work    
##`zfs <command>` >> output.txt 2>&1  #doesn't work    

This creates a output.txt of size 0 bytes and error message is displayed on the command prompt.

 sudo ./testShell.sh    
cannot load key for '/tank/test1': incorrect key.    

Any inputs, please?

Upvotes: 2

Views: 684

Answers (1)

John1024
John1024

Reputation: 113924

This does not do what one might expect:

`zfs <command>` 2>&1 | tee file.txt

The above command executes zfs <command>, collects the standard out from that command and treats that output as if it were a command and tries to execute it.

In all likelihood, you just want zfs <command> executed and its output redirected. In that case:

zfs <command> 2>&1 | tee file.txt

Upvotes: 3

Related Questions