Operating System - HP-UX
1827807 Members
2742 Online
109969 Solutions
New Discussion

Re: readonly variable in /etc/profile

 
Rex Pommier
Frequent Advisor

readonly variable in /etc/profile

Hi. I am wondering what I'm doing wrong. I am trying to set the TMOUT variable in /etc/profile and it appears that HP-UX is ignoring any statements after the readonly statement. But here's the truly bizarre part of it. If I use TeraTerm the profile runs correctly, but if I use telnet through Hummingbird Exceed, the profile stops executing code at the readonly statement!

Following is a snippet of the code.

ulimit -n 2000
ulimit -c 0
echo after ulimit stmts >>/tmp/logindebug
# Set a timeout variable to 30 minutes
readonly TMOUT=1800
echo after the readonly stmt >>/tmp/logindebug
export TMOUT
echo got to number 3 >>/tmp/logindebug
echo 3 $PATH >>/tmp/logindebug

The last line I get in the /tmp/logindebug file is "after ulimit stmts".

The other thing I noticed which I don't know if it makes any difference is that my TERM variable is set to vt100 in TeraTerm and xterm in Exceed.

Has anybody run into this or does anybody have any ideas?

Thanks.
13 REPLIES 13
Sanjay_6
Honored Contributor

Re: readonly variable in /etc/profile

Hi,

Use the statement like this,

TMOUT=1800
readonly TMOUT
export TMOUT

Hope this helps.

Regds
Sanjay_6
Honored Contributor

Re: readonly variable in /etc/profile

Hi Rex,

When opening an exceed telnet window, use the option "-ls". This is used to tell xterm or hpterm to create the new window as a login shell. This will force the use of
the .profile file.

Hope this helps.

Regds

Rex Pommier
Frequent Advisor

Re: readonly variable in /etc/profile

Sanjay,

Splitting out the setting of the variable and making it readonly made no difference. But, when I split it apart and put an echo between the TMOUT=1800 statement and the export TMOUT statement, I didn't get a response to the echo.

I also checked the -ls option in Exceed and it is already there.
RAC_1
Honored Contributor

Re: readonly variable in /etc/profile

typeset -r TMOUT=xxx
export TMOUT

Does it help???

Anil
There is no substitute to HARDWORK
Sanjay_6
Honored Contributor

Re: readonly variable in /etc/profile

Hi Rex,

You can try the xterm and profile issue this way.

create a file .Xdefaults in the $HOME
chmod 755 $HOME/Xdefaults

Add this entry to this file,

*loginShell: true

Hope this helps.

Regds
Rex Pommier
Frequent Advisor

Re: readonly variable in /etc/profile

Neither suggestion worked. I appreciate the help, though.
Rex Pommier
Frequent Advisor

Re: readonly variable in /etc/profile

Here's the latest. I opened a case with HP on it and as of yet they haven't any ideas. The person I talked to did give me a different way of going about this and here's the summary:

readonly TMOUT=1800
export TMOUT

causes everything after the "readonly" statement in /etc/profile to be ignored. BTW, /$HOME/.profile still executes!

typeset -r TMOUT=1800
export TMOUT

does the same thing as above

export & readonly TMOUT=1800

WORKS!!!!!
Todd McDaniel_1
Honored Contributor

Re: readonly variable in /etc/profile

Looks like you have it solved, but I will mention this anyway.

Put these statements at the end of your .profile and see what that does with the other non-working versions and see what you get.

just for testing.
Unix, the other white meat.
Bill Hassell
Honored Contributor

Re: readonly variable in /etc/profile

Actually, you can combine readonly and export as in:

readonly export TMOUT=1800

Something that will assist a lot in debugging profiles (and any scripts) is: set -x. This turns on tracing so you never need any echo statements to figure out what happened. You can also run your script with:

sh -x /etc/profile

and since the debugging output goes to stderr, you can use more or pg as in:

sh -x .profile 2>&1 | more

As far as setting TERM, always let ttytype set your TERM variable. You NEVER want to hardcode this value because you can't guarentee what users will be running when they login. Put this in /etc/profile:

eval $(ttytype -s)

To see what ttytype is dpoing, just type the command: ttytype -s

As far as the effect of changing TERM, this is a critical variable that tells applications how your terminal behaves. There are more than a thousand terminal entries in the /usr/bin/terminfo directory and they control what special character sequences are needed by programs that use Curses library calls. To see the differences between vt100 and xterm (and there are a lot):

untic vt100
untic xterm

A menu program like sam or glance or swinstall will looked very messed up if your TERM variable has nothing to do with the termi al that you are using.


Bill Hassell, sysadmin
Rex Pommier
Frequent Advisor

Re: readonly variable in /etc/profile

Todd, your reply caused me to play some more with this. I tried what you said, moving the readonly and export to .profile with the same effect. Everything after the readonly stmt was ignored. I then did some more testing and found that apparently the problem isn't in the readonly stmt but in the export stmt following it. It appears that making a variable readonly implicitly does an export of the variable. Here is what happened. If I just use the readonly stmt, the variable follows me around and is indeed readonly. If I follow the readonly with an export stmt, the export generates an error telling me that the variable is readonly and everything is ignored from that point on. Just to prove my point, I plugged the following snippet into the profile

readonly TMOUT=1800
echo past the readonly
readonly JUNK=whyme?
echo past the second readonly
export JUNK

I got the first echo output but not the second. I got the error message stating that JUNK was readonly and everything following was ignored. Interesting.

Bill,

Good point on the set -x . I keep forgetting that is there. Obviously I don't do much shell scripting! Also, I probably wasn't very clear but I wasn't setting the TERM variable. I am using ttytype to let the system set the TERM variable for me. I was merely pointing out what the settings of the variables were, thinking the different settings may have had a bearing on the problem I was having. Also, thanks for a different thread where you talked about the TSET command being outdated. I have the ttytype command in /etc/profile but somebody stuck the TSET in some .profile files and my emulated vt220 screens with non-default lines per screen wouldn't scroll the screen. I removed the TSET based on your other post and everything started scrolling like it should again.
Bill Hassell
Honored Contributor

Re: readonly variable in /etc/profile

readonly (once set) means that modifications to the variable are no longer allowed, If TMOUT was set to readonly in /etc/profile, then any attempt to define it again (even if it's the same value) will give you the readonly error message. The reason that things get ignored after the error is that the error is terminating the script. This where set -x in /etc/profile works well. Try a grep for TMOUT and see if it appears several times in profile.


Bill Hassell, sysadmin
Rex Pommier
Frequent Advisor

Re: readonly variable in /etc/profile

Bill,

I only have the TMOUT variable being set once. The error was occurring on the export command. To me it doesn't make any sense that exporting a variable that is defined as readonly should throw the error since exporting the variable doesn't change the value of it. It makes sense that once the error message is generated that the script stops running, it just doesn't make sense that the error should be generated in the first place.

Rex
Bill Hassell
Honored Contributor

Re: readonly variable in /etc/profile

It may be a shell bug...I tried it on 11.11 with 2004 patch bundles and found export did not have an error. Both POSIX shell and ksh will report an error whenever the variable was previously defined as readonly and then appears later with an = sign as in TMOUT=1234


Bill Hassell, sysadmin