When I try to run a command on a remote host

ssh user@example.com "fswebcam -d /dev/video0 --save -" > img1

I always get at the top of the img1 file mixed in

^]kfswebcam -r 1280x960 -d /dev/video0 --save -\ÿØÿàJFIFÿþ>CREATOR: gd-jp

Which causes the file to no longer be a valid JPEG image


I found the issue.
It's in the fish shell, when I run /bin/bash ssh user@example.com "fswebcam -d /dev/video0 --save -" > img1 it works perfectly fine.
No mixed up headers in the jpeg image

  • I was wondering if it was the shell... Makes since – PlasmaPower Mar 23 '14 at 23:38

This seems to be some echo configuration on the example.com host. I just tested with ssh localhost date and it will just print the date without any echo of the date command. Try to confirm this by running date and check if that also gets a first line of echo.

Try to temporarily disable files like .bashrc, .profile, etc by renaming or moving out of the home directory and see if you still get echo. Does changing the login shell for user to /bin/sh make any difference?

  • No, running date is fine. It's only when it's being outputted through pipe it seems. Which is very odd but also indicates it might be my osx behaving odd – Botto Mar 23 '14 at 23:33
  • Any pipe? What about ssh localhost date | cat?. – hlovdal Mar 23 '14 at 23:44

A rather roundabout way of doing it, but you could use:

ssh user@example.com "fswebcam -d /dev/video0 --save -"  | tail -n +2 > img1
  • sed 1d could alternatively be used instead of the head command. – hlovdal Mar 23 '14 at 23:26
  • Won't work - using head -n -1 will get rid of the last line of the file, not the first. You want to do this: ssh user@example.com "fswebcam -d /dev/video0 --save -" | tail -n +2 > img1 EDIT: @hlovdal is correct as well. – user55325 Mar 23 '14 at 23:26
  • @user55325 Oops! Thanks for pointing that out! – PlasmaPower Mar 23 '14 at 23:27
  • If it had only been that easy, unfortunately it's mixed in. I've updated the question – Botto Mar 23 '14 at 23:31

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.