Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

i am trying to run a bash script on a remote machine. If I open a ssh connection in a terminal, i can easily run the script. But when i run it like that:

ssh user@ip < /etc/script

I get an Error:

TERM enviroment variable not set.

What am i doing wrong here?

share|improve this question

Using ssh's -t option might solve your problem, since it connects a tty and sets an appropiate TERM environ variable.

ssh -t host < script

share|improve this answer

When you redirect input, ssh client probably realizes input is not connected to a TTY and so decides TERM is inappropriate.

share|improve this answer

Experiment with putting these lines in ~user/.bashrc on the destination host:

if [ ! ${#TERM} > 0 ]
    export TERM=<value>

${#var} returns the string length of variable var. So, if the length of TERM is NULL (unset) or 0, you can manually set your TERM value.

You can also think about testing whether $SSH_CLIENT or $SSH_CONNECTION are non-zero, and only testing for a TERM value under those conditions.

Finally, this needs to go in .bashrc because .bash_login only gets run on login shells.

share|improve this answer
Unfortunatelly i can not change any files on the host/localmachine, as they are servers, that have to stay like they are. I am only allowed to change the script, which is located on both machines... – Simons0n Nov 5 '12 at 13:26
In that case, since you script is also bash, you can experiment with setting the lines in your script. – dafydd Nov 6 '12 at 22:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .