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.

link|improve this question
feedback

2 Answers

up vote 3 down vote accepted

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?

link|improve this answer
You are right, ssh <host> '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
feedback

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.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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