Q: Remote SSH Gnu/Linux server isn't recognizing my pipe Basically I'm trying to run the following command:
sshpass -p "xxx" ssh root@x.x.x.x "tail -f /tmp/messages | grep ptp4l" | cat -n > output.txt

I'm trying to get tmp/messages to continually write to a local file so some of our techs can continually monitor IEEE 1588v2 offsets from their master without having to understand anything about the Gnu/Linux server they're accessing.
When I run this command I get no output, to my file at all.
When I manually run the command:
tail -f /tmp/messages | grep ptp4l

all is good and I have no problems at all. I get the output that I'm looking for.
Am I missing anything? Can you not send a pipe through a quoted command?
Thanks,
Stephen

A: This is the classical "writing to a pipe is fully buffered" problem.
Try either forcing your ssh to allocate a pseudo-tty on the remote machine with -tt or use the --line-buffered option to grep, if it accepts that option.
ssh ... -tt </dev/null 'tail -f /tmp/messages | grep ptp4l' | cat -n > output.txt

ssh ... 'tail -f /tmp/messages | grep --line-buffered ptp4l' | cat -n > output.txt

The </dev/null redirection when allocating a tty on the remote machine is in order to prevent ssh from messing with the local tty (by putting it in raw mode), which is a side effect of the -t switch. You can do that with any ssh command which is not using the stdin (if necessary, the ssh client will open /dev/tty to read its password, it will not use stdin for that).
