Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

3 Answers

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
add comment

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

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

${#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
add comment

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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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