Ambiguous output redirect in xterm

Hi all,

I've been working on a bash script to help with backups that I have to do at work.

One of the lines in the script is supposed to launch an xterm, log into a specific server node and launch a tar backup to tape. This part works ok, but I've been trying to get stdout and stderr to display in the xterm and output to a log file using tee.

To this end, this is my current code:

xterm -hold -e "rsh amaqc01 tar -cvML471859200 -f amatap0"$tape_nd":/dev/st"$tape_dr" /dir1/dir2 2>&1 | foo/bar.txt" &

When the script launches this though, the xterm presents an 'Ambiguous output redirect' error.

I suspect that this is actually due to the system using csh as the default shell such that the xterm is actually running csh rather than bash.

I've tried

xterm -hold -e "bash; rsh amaqc01"

to fix this but this seems to end up opening the xterm, running the rsh and THEN running bash.

So I guess my question is, what am I missing? Is it even possible to achieve what I'm trying and if so, how?

Thanks in advance

What you want is

xterm -hold -e "sh -c 'rsh amaqc01 tar -cvML471859200 -f amatap0"$tape_nd":/dev/st"$tape_dr" /dir1/dir2 2>&1' | foo/bar.txt" &

Or you can code it for csh (only):

xterm -hold -e "rsh amaqc01 tar -cvML471859200 -f amatap0"$tape_nd":/dev/st"$tape_dr" /dir1/dir2 |& foo/bar.txt" &

Do you really need to capture stderr in foo/bar.txt?
If not, in your current script you can simply omit the 2>&1 .

1 Like

Thanks for that. The first suggestion didn't work (I think the single quotes prevented the variables from being treated as such).

However the second suggestions works fine. One thing I didn't realise though is that it doesn't write out the output to the log as its created but appears to buffer it somewhere before logging all output in one go. This isn't a problem though! Just an observation :slight_smile:

Thanks!