LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-19-2007, 10:47 PM   #1
vikas027
Senior Member
 
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Ubuntu, Debian, OS X
Posts: 1,305

Rep: Reputation: 107Reputation: 107
Unhappy TERM environment variable not set


I am getting this error while executing this script
"TERM environment variable not set"

Here is my script:

Code:
#!/bin/bash
showMenu ()
{
echo "1) Cont"
echo "0) Exit"
}

while [ -r IP.txt ]
do
showMenu
read ch
case "$ch" in
"1")
        echo "Enter IP"
        read IP
        ssh -l root $IP "top -n1;" > final
        ;;

"0")
        exit ;;

esac
done

Also, there is no crontab in my machine.


Please help !!

Last edited by vikas027; 10-20-2007 at 12:09 PM. Reason: forgot something
 
Old 10-20-2007, 11:13 AM   #2
PAix
Member
 
Registered: Jul 2007
Location: United Kingdom, W Mids
Distribution: SUSE 11.0 as of Nov 2008
Posts: 195

Rep: Reputation: 40
Hi, if you go into your post and edit the [ quote ] and [ / quote ] tags, changing them for [ code ] and [ / code ] then the indenting of your code will be easier for readers and anyone cutting and pasting your code to check it out for you. ( take the spaces out of the tags of course - here so that you can see them properly).

Also please edit your profile to indicate the distribution that you are using. It may well help with this type of enquiry.

Check out the crontab man page:
Code:
crontab [ -u user ] filename
The first form of this command is used to install a new  crontab  from  some
named file or standard input if the pseudo-filename ``-'' is given.
There probably isn't a crontab file by default.

Set up a file, call it something like "mycrontab" and put in something like
Code:
30 18 * * 1 /home/youruser/yourcommand < your inputfile> youroutput file
The first five fields must be set, with values or stars. This decodes as run yourcommand at 18:30 every Monday and here you can specify input and output files by redirection if you wish. Not something you can do with the at command.
Submit the command using
Code:
crontab mycrontab
#Check the queue using 
crontab -l
You may need your username in the cron.allow file. As I said, check the man page and Google "crontab" and have a look at "setting up cron jobs using crontab".

I avoided the -e option like the plague, too complicated for a simple soul like me. I merely edited my mycron file, removed the current cron file with crontab -r and created a new one as described above.

I was playing with at a short while ago and found that I had to start the at daemon. You may possibly find that the cron daemon is not started, but that seems unlikely.
Hopefully someone will be able to help you with your script.



PAix

Last edited by PAix; 10-20-2007 at 11:51 AM. Reason: additional info
 
Old 10-20-2007, 01:06 PM   #3
bgoodr
Member
 
Registered: Dec 2006
Location: Oregon
Distribution: RHEL[567] x86_64, Ubuntu 17.10 x86_64
Posts: 221

Rep: Reputation: 36
Hi vikas027:

Do you know if you are getting the "TERM environment variable not set" while executing the script from within the crontab environment, or directly from a terminal window?

bgoodr
 
Old 10-20-2007, 04:29 PM   #4
PAix
Member
 
Registered: Jul 2007
Location: United Kingdom, W Mids
Distribution: SUSE 11.0 as of Nov 2008
Posts: 195

Rep: Reputation: 40
Cron invokes the command from the user's HOME directory with the shell, (/usr/bin/sh).
cron supplies a default environment for every shell, defining:
HOME=user's-home-directory
LOGNAME=user's-login-id
PATH=/usr/bin:/usr/sbin:.
SHELL=/usr/bin/sh

Users who desire to have their .profile executed must explicitly do so in the crontab entry or in a script called by the entry.

That might be a worth knowing.
 
Old 10-20-2007, 11:17 PM   #5
vikas027
Senior Member
 
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Ubuntu, Debian, OS X
Posts: 1,305

Original Poster
Rep: Reputation: 107Reputation: 107
Unhappy

Quote:
Originally Posted by bgoodr View Post
Hi vikas027:

Do you know if you are getting the "TERM environment variable not set" while executing the script from within the crontab environment, or directly from a terminal window?

bgoodr


I am getting this error while executing script direct from terminal window. I dont have crontab on my system.
 
Old 10-21-2007, 04:55 PM   #6
PAix
Member
 
Registered: Jul 2007
Location: United Kingdom, W Mids
Distribution: SUSE 11.0 as of Nov 2008
Posts: 195

Rep: Reputation: 40
Hmmmm. So has the fact that you don't have crontab on your box a total irrelevance or is there something that you know but are failing to tell us?

The script as written doesn't work. function showMenu () instead of showMenu () in line 1 will fix that though.

So what you are actually saying is, if you execute the following at the command line, it
[code]ssh -l root "localhost" "top -nl;"[code]is returning with "TERM environment variable is not set"?
This is a minimal test case and if this fails then it's an indication that the script is in not really part of the problem. You can of course substitute your favourite IP address for localhost if you wish.
What does
Code:
env | grep TERM > result.txt
return in result.txt? Well if it isn't redirected into the file you shoud probably see something like TERM=xterm. If you put it in a shellfile and execute it as ./shellfile you will get much the same. BUT if you execute it with at -f shellfile xx:xx then it will not find TERM in the env list. Because there is no terminal associated with the batch. The same goes for CRON and when you arrive at your destination with ssh do you have a terminal available? perhaps asking ssh for the env |grep TERM will give some clues.

So is it likely that your top command executing on the remote platform probably also has no terminal, but is TERM expected by top and being disapointed?

I may well be wrong, but I think these are a few things to think about in your search.

Good luck PAix

PS - Your code, corrected by the addition of function as mentioned above and given "localhost" as the IP; I got the following, but then I don't know much about my ssh setup.

ssh -l root Localhost "top -nl;"
The authenticity of host 'localhost (127.0.0.1)' can't be established.
RSA key fingerprint is af:14:f8:ab:46:b1:c5:db:f1:14:22:54:71:ff:c4:6c.
Are you sure you want to continue connecting (yes/no)? no
Host key verification failed.


Actually I think you got this answer to your post here:http://www.linuxquestions.org/questi...ng-ssh-593398/

Last edited by PAix; 10-21-2007 at 08:25 PM.
 
Old 10-23-2007, 09:13 AM   #7
vikas027
Senior Member
 
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Ubuntu, Debian, OS X
Posts: 1,305

Original Poster
Rep: Reputation: 107Reputation: 107
Quote:
Originally Posted by PAix View Post
Hmmmm. So has the fact that you don't have crontab on your box a total irrelevance or is there something that you know but are failing to tell us?

The script as written doesn't work. function showMenu () instead of showMenu () in line 1 will fix that though.

So what you are actually saying is, if you execute the following at the command line, it
[code]ssh -l root "localhost" "top -nl;"[code]is returning with "TERM environment variable is not set"?
This is a minimal test case and if this fails then it's an indication that the script is in not really part of the problem. You can of course substitute your favourite IP address for localhost if you wish.
What does
Code:
env | grep TERM > result.txt
return in result.txt? Well if it isn't redirected into the file you shoud probably see something like TERM=xterm. If you put it in a shellfile and execute it as ./shellfile you will get much the same. BUT if you execute it with at -f shellfile xx:xx then it will not find TERM in the env list. Because there is no terminal associated with the batch. The same goes for CRON and when you arrive at your destination with ssh do you have a terminal available? perhaps asking ssh for the env |grep TERM will give some clues.

So is it likely that your top command executing on the remote platform probably also has no terminal, but is TERM expected by top and being disapointed?

I may well be wrong, but I think these are a few things to think about in your search.

Good luck PAix

PS - Your code, corrected by the addition of function as mentioned above and given "localhost" as the IP; I got the following, but then I don't know much about my ssh setup.

ssh -l root Localhost "top -nl;"
The authenticity of host 'localhost (127.0.0.1)' can't be established.
RSA key fingerprint is af:14:f8:ab:46:b1:c5:db:f1:14:22:54:71:ff:c4:6c.
Are you sure you want to continue connecting (yes/no)? no
Host key verification failed.


Actually I think you got this answer to your post here:http://www.linuxquestions.org/questi...ng-ssh-593398/



hey, I did
Code:
env | grep TERM > result.txt
i got TERM=linux in the file

Also, this code works just fine.

Code:
# ssh IP "top -b -d1"
or 
# ssh IP "top -b -n1"
My problem solved.

THANKS TO ALL, YOU PEOPLE HELP SO MUCH.
THANKS A TON.

Last edited by vikas027; 10-23-2007 at 09:16 AM. Reason: forgot something
 
  


Reply



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
How to set environment variable yuan13452 Linux - Software 7 09-03-2007 05:23 PM
Use of TERM environment variable saandeep_jan Linux - Newbie 1 08-30-2007 03:55 PM
Where is global TERM variable set? tonyfreeman Red Hat 1 02-20-2007 02:20 PM
scp error, TERM env. variable not set? jimbo Linux - Networking 2 11-26-2005 01:31 AM
Cron: TERM environment variable not set. hydro Linux - General 4 04-15-2004 10:59 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:31 AM.

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
Open Source Consulting | Domain Registration