Topic: https://brettterpstra.com/2014/02/19/remote-pbcopy-on-os-x-systems/
hide preview

What's next? verify your email address for reply notifications!

unverified 5y, 314d ago

I thought this would be handy so I gave it a try. I can't get it to work at all with the RemoteForward line in ~/.ssh/config. If I use "-R2224:localhost:2224" on the command line it works on Debian and Ubuntu, but not on RedHat.

hide preview

What's next? verify your email address for reply notifications!

Daniel 11y, 27d ago

Thanks for forwarding Seans great tip.

A few of questions though:

1. Do you really need the `-c`-flag (or the `-q1` in Seans version). To me it seems like it works without it? I've seen `-q1` used with UDP, but this is through TCP, insn't it? And according to my man page on OSX `nc`, `-c` means "Send CRLF as line-ending".
2. What benefit is there to piping through `cat`? My `nc` seems to handle stdin just lik cat. What am I missing?
3. Why do you set a variable based on `[ -n $SSH_CLIENT]` rather than using that directly in the `if`-statement?

Please note that I'm just curious, not trying to be a smart ass. There is a lot of things I don't know about shell scripts, so I'm asking to learn.

remark link
hide preview

What's next? verify your email address for reply notifications!

ttscoff 11y, 27d ago

If you don't use -c, the script will just hang waiting for more input.

cat allows you to take STDIN input in a shell script.

I have a reusable snippet for setting the SSH_CLIENT variable that I use in scripts that have more logic. It's just easier.

remark link parent
hide preview

What's next? verify your email address for reply notifications!

Daniel 11y, 27d ago

Using -c on Mavericks only gives me a CRLF last in the output (Seen as ^M in VIM). Are we using different versions of nc?

And I see no difference in behavior of the script if I remove "cat |" from it.

I ended up with this line in .bashrc:

[ -n "$SSH_CLIENT" ] && alias pbcopy="nc localhost 2224"

Works so far, but I guess there is some scenario when it'll come back and bite me.

Anyway, thanks again for a great tip!

remark link parent
hide preview

What's next? verify your email address for reply notifications!

ttscoff 11y, 27d ago

Also, your script is using alias instead of actually piping to the script. It works, just a different strategy. Thus you don't need cat.

remark link parent

load more (1 remarks)
hide preview

What's next? verify your email address for reply notifications!

Daniel 11y, 27d ago

Yes I ended up using only an alias, but I tested it in the script first, with and without cat. Thus I still don't know why you need cat. (Not saying you don't, just that I haven't seen why yet.)

hide preview

What's next? verify your email address for reply notifications!

ttscoff 11y, 27d ago

It's quite possible that I've installed a version of netcat from brew. If I `cat testfile.txt | nc localhost 2224` it just sits there and waits for a ^d. -c fixes that.

remark link parent

load more (1 remarks)
hide preview

What's next? verify your email address for reply notifications!

Daniel 11y, 27d ago

That works for me, so most likely we have different versions. My nc sits in /usr/bin so I'm quite sure I haven't installed it myself.

hide preview

What's next? verify your email address for reply notifications!