LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-30-2013, 08:20 AM   #1
Rohit_4739
Member
 
Registered: Oct 2010
Distribution: Red Hat
Posts: 228

Rep: Reputation: 9
TERM environment variable not set


Hi All,

I am trying to execute a bash script from a centralized AIX machine to Linux boxes but i get the error saying "TERM environment variable not set". Below are my scripts and how i am using them to execute remotely.
Code:
serv1:/ #ls -l rohit.sh
-rw-r--r--    1 root     system          333 May 30 07:14 rohit.sh
Code:
#!/bin/bash
clear
echo -e "\n"
IFS=$','
LIST="Test1,Test2,Test3,Exit"
PS3="Please enter your choice : "

select i in $LIST
do
clear
case $i in
         "Test1" )
          echo "Hello1;;
        "Test2" )
          echo "Hello3;;
        "Test3" )
           echo "Hello3";;
              "Exit" )
        exit 0;;
esac
done
This is how i am executing the script.
Code:
serv1:/ #ssh serv2 'bash' < rohit.sh
And below is the output i see

Code:
serv1:/ #ssh serv2 'bash' < rohit.sh


TERM environment variable not set.1) Test1
2) Test2
3) Test3
4) Exit
Please enter your choice :
TERM environment variable not set.
Please enter your choice : serv1:/ #
As you can see the script has terminated and i am back the prompt.

So can anyone suggest. I also tried setting the TERM=xterm and then exporting it in the script but even that also didn't help.
 
Old 05-30-2013, 09:24 AM   #2
linosaurusroot
Member
 
Registered: Oct 2012
Distribution: OpenSuSE,RHEL,Fedora,OpenBSD
Posts: 979
Blog Entries: 2

Rep: Reputation: 235Reputation: 235Reputation: 235
When you are running a remote command like that you don't get a terminal. I wouldn't include the "clear" commands.
 
Old 05-30-2013, 09:38 AM   #3
Rohit_4739
Member
 
Registered: Oct 2010
Distribution: Red Hat
Posts: 228

Original Poster
Rep: Reputation: 9
hi linosaurusroot, thanks for yuor reply.removing "clear" actually resolved the error but i still end up at the prompt without my script being executed.

Here is the output after removing "clear" from the script

Code:
serv1:/ #ssh serv1 'bash' < rohit.sh


1) Test1
2) Test2
3) Test3
4) Exit
Please enter your choice : Please enter your choice :
serv1:/ #
Anything you can suggest.

Last edited by Rohit_4739; 05-30-2013 at 09:43 AM.
 
Old 05-30-2013, 09:43 AM   #4
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
Perhaps the terminal type is not defined. What's result of:
Code:
~$ env | grep TERM
EDIT: Invoke your script with -xv debug option, and see where it goes wrong, as:
Code:
serv1:/ # ssh serv2 'bash -xv rohit.sh'

Last edited by shivaa; 05-30-2013 at 09:47 AM.
 
Old 05-30-2013, 09:48 AM   #5
Rohit_4739
Member
 
Registered: Oct 2010
Distribution: Red Hat
Posts: 228

Original Poster
Rep: Reputation: 9
Quote:
Originally Posted by shivaa View Post
Perhaps the terminal type is not defined. What's result of:
Code:
~$ env | grep TERM
Code:
#env | grep TERM
TERM=xterm
The error related to "TERM" has been resolved but i am still unable to figure out why my scripts is just exiting ??????? There is no issue with the script because i copied the script the linux box (serv2)then executed it and it worked just fine. However when i am trying to execute from remote aix box which is serv1 then it just exits without executing and comes back at the prompt.

Last edited by Rohit_4739; 05-30-2013 at 10:15 AM.
 
Old 05-30-2013, 11:23 AM   #6
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,396
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
The problem you're having is because you seem to be mistaken about where your standard IO redirection is occurring. The local host is redirecting the standard input of the ssh process from the script 'rohit.sh'. I surmise that your intention is to run the script under the bash process on the remote host. In order for that to happen, the script must exist on that remote host. The redirection you're using probably does nothing, since ssh doesn't know what to do with a shell script as input.
--- rod.
 
Old 05-30-2013, 11:31 AM   #7
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
Quote:
Originally Posted by Rohit_4739 View Post
However when i am trying to execute from remote aix box which is serv1 then it just exits without executing and comes back at the prompt.
Did you try?
Code:
serv1:/ # ssh serv2 'bash -xv rohit.sh'
#Or
serv1:/ # ssh serv2 'bash rohit.sh'
 
Old 05-31-2013, 03:37 AM   #8
Rohit_4739
Member
 
Registered: Oct 2010
Distribution: Red Hat
Posts: 228

Original Poster
Rep: Reputation: 9
Quote:
Originally Posted by theNbomr View Post
The problem you're having is because you seem to be mistaken about where your standard IO redirection is occurring. The local host is redirecting the standard input of the ssh process from the script 'rohit.sh'. I surmise that your intention is to run the script under the bash process on the remote host. In order for that to happen, the script must exist on that remote host. The redirection you're using probably does nothing, since ssh doesn't know what to do with a shell script as input.
--- rod.
But if the script must exist on the remote server then i think sole purpose is being defeted here, for example if i have 1000 servers and i want to run the script from centralized server by just providing the hostname like below.
Code:
ssh <hostname> 'bash' < script.sh
How do i do so then
 
Old 05-31-2013, 03:38 AM   #9
Rohit_4739
Member
 
Registered: Oct 2010
Distribution: Red Hat
Posts: 228

Original Poster
Rep: Reputation: 9
Quote:
Originally Posted by shivaa View Post
Did you try?
Code:
serv1:/ # ssh serv2 'bash -xv rohit.sh'
#Or
serv1:/ # ssh serv2 'bash rohit.sh'
Yes i tried and as i wrote earlier there is no bug in the script as it executed just fine on the remote machine by copying the script on the machine .
 
Old 05-31-2013, 09:32 AM   #10
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,396
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
If the script cannot be on the remote host, then your only recourse will be to feed the content of the script through the ssh connection. Probably the expect tool is the best way to accomplish that. You may also be able to run the ssh session from within a screen session. Using that method, you will be able to exploit screen's stuff command to push data into the screen session, and thus to the remote bash session. I have used this method with very good success in similar applications.

What about your local script including a line that uses scp to put the script onto the remote host before executing it? Your local script could then probably delete it from the remote host before closing the connection.

--- rod.
 
Old 05-31-2013, 10:06 AM   #11
Rohit_4739
Member
 
Registered: Oct 2010
Distribution: Red Hat
Posts: 228

Original Poster
Rep: Reputation: 9
Quote:
Originally Posted by theNbomr View Post
If the script cannot be on the remote host, then your only recourse will be to feed the content of the script through the ssh connection. Probably the expect tool is the best way to accomplish that. You may also be able to run the ssh session from within a screen session. Using that method, you will be able to exploit screen's stuff command to push data into the screen session, and thus to the remote bash session. I have used this method with very good success in similar applications.

What about your local script including a line that uses scp to put the script onto the remote host before executing it? Your local script could then probably delete it from the remote host before closing the connection.

--- rod.
Yes i did used the 2nd method you specified, i mean first copying the script using SCP, then executing it using SSH and then removing it from remote server. I did like below

Code:
scp rohit.sh root@serv2:/root >/dev/null
ssh serv2 'bash' '/root/rohit.sh; rm -f /root/rohit.sh'
However the concern i have with this that it will affect performance as first the script has to be copied and then executed. I tried running the script using Screen also but that also didn't work. COuld you please share with me how you have used screen in the past successfully in the past. Also if you have any idea on how to do that via Expect ?
 
Old 05-31-2013, 10:52 AM   #12
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,396
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Never had to use expect, since I always use the screen method. expect is probably required if you need to send data that depends on some condition observed in the response from the remote host.
This should get you close, using the screen method:
Code:
NL=$(echo -ne '\015')
screenName=rohitsAppl
screen -S ${screenName} -dm
sleep 1
screen -S ${screenName} -p 0 -X stuff "ssh serv2${NL}"

while read script; do
    screen -S ${screenName} -p 0 -X stuff "${script}${NL}"
done < rohit.sh

screen -S ${screenName} -p 0 -X stuff "exit${NL}"
screen -S ${screenName} -p 0 -X stuff "exit${NL}"
You can hardcode the strings you want to stuff into the session, rather than reading the existing script. The ${NL} is the stuff equivalent of pressing the 'enter' key. The sleep is necessary to allow the session to start up and be in a state to accept further commands. You might need another one or two second sleep following the ssh login command.

--- rod.

Last edited by theNbomr; 05-31-2013 at 10:55 AM.
 
Old 05-31-2013, 04:20 PM   #13
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,604

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
Quote:
Originally Posted by Rohit_4739 View Post
Hi All,

I am trying to execute a bash script from a centralized AIX machine to Linux boxes but i get the error saying "TERM environment variable not set". Below are my scripts and how i am using them to execute remotely.

...

This is how i am executing the script.
Code:
serv1:/
And below is the output i see

Code:
serv1:/ #ssh serv2 'bash' < rohit.sh


TERM environment variable not set.1) Test1
2) Test2
3) Test3
4) Exit
Please enter your choice :
TERM environment variable not set.
Please enter your choice : serv1:/ #
As you can see the script has terminated and i am back the prompt.

So can anyone suggest. I also tried setting the TERM=xterm and then exporting it in the script but even that also didn't help.
It is relatively simple:

ssh -t serv2 'bash' < rohit.sh

giving a command (such as 'bash') causes ssh to not request a terminal.

You also get a working result using

ssh serv2 <rohit.sh

as that requests a terminal to be assigned.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
TERM environment variable not set 786 Linux - General 7 07-15-2008 05:20 PM
[SOLVED] TERM environment variable not set vikas027 Programming 6 10-23-2007 10:13 AM
Use of TERM environment variable saandeep_jan Linux - Newbie 1 08-30-2007 04:55 PM
Where is global TERM variable set? tonyfreeman Red Hat 1 02-20-2007 03:20 PM
Cron: TERM environment variable not set. hydro Linux - General 4 04-15-2004 11:59 PM


All times are GMT -5. The time now is 10:27 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration