1

I have a remote (linux) server that I ssh to from my (also linux) pc to print my stuff.

Everything works if I do:

    ssh ${remote_server}
    (now in remote server)
    lpr readme.txt

Or:

    ssh ${remote_server} lpr readme.txt -P$PRINTER
    (this works too)

But if I do:

    ssh ${remote_server} lpr readme.txt 
    (I get a "there-is-no-default-printer" error.)

I did set the $PRINTER environment variable such that "ssh echo $PRINTER" gives me the right printer name.

alexloh
  • 113
  • 3

2 Answers2

3

Note that running:

ssh <host> echo $PRINTER

...tells you nothing about the remote environment, because $PRINTER will be expanded by your local shell. On the other hand:

ssh <host> 'echo $PRINTER'

...will tell you something useful (note the single quotes).

I suspect that what's happening is that you're setting the PRINTER environment variable in a file that only gets sourced for interactive logins. Are you using bash? Or something else? Where are you setting PRINTER?

larsks
  • 41,276
  • 13
  • 117
  • 170
  • You are right, ssh 'echo $PRINTER' produces a blank. I set it in both bashrc and bash_profile. Which is the correct place to set it? – alexloh Jun 25 '11 at 14:33
0

It could be that $PRINTER is set in /etc/profile or ~/.profile, which is ignored for non-interactive sessions.

Your test – ssh echo $PRINTER – is invalid, as the variable is expanded locally, and what gets executed is ssh echo printername.

user1686
  • 8,717
  • 25
  • 38