cancel
Showing results for 
Search instead for 
Did you mean: 

Best practice for setting an environment variable used during NW AS startup

tim_alsop
Active Contributor
0 Kudos

We have installed some code which is running in both the ABAP and JAVA environment, and some functionality of this code is determined by the setting of operating system environment variables. We have therefore changed the .sapenv_<host>.csh and .sapenv_<host>.sh scripts found in the <sid>adm user home directory. This works, but we are wondering what happens when SAP is upgraded, and if these custom shell script changes to the .sh and .csh scripts will be overwritten during such an upgrade. Is there a better way to set environment variables so they can be used by the SAP server software when it has been started from <sid>adm user ?

Accepted Solutions (1)

Accepted Solutions (1)

former_member698570
Active Participant
0 Kudos

Hi,

I'm quite sure the Shell Scripts are being overwritten when you apply an SP-Stack (at least for JAVA Stack. I'm not sure for ABAP Stack)

But the best way to avoid this is doing the following:

Create a custom script e.g. myscript_env.sh or .csh or whatever and add the script to the profile (.profile file in the home directory of the sidadm => That's where SAP puts its scripts too) of the sidadm user. This way this script will always be executed when switching to sidadm even if the scripts provided by SAP are overwritten when upgrading

Add something like

## Setting My Environment
if [ -f $HOME/.myscript_env.sh ]; then
     . $HOME/.myscript_env.sh ];
fi

at the end of the file

I think it's the best way

Hope this helps

Cheers

tim_alsop
Active Contributor
0 Kudos

Marcel,

Thankyou. I was concerned that if I did that there might be a case where the .profile is not used, e.g. when a non-interactive process is started I was not sure if .profile is used.

Also, on one of my servers I have a .profile a .login and also a .cshrc file. Do I need to update all of these ?

In my /etc/passwd the <sid>adm user is configured with /bin/csh shell, so I think this means my .cshrc will be used and not the .profile ? Is this correct ?

Thanks,

Tim

former_member698570
Active Participant
0 Kudos

Hi,

Thankyou. I was concerned that if I did that there might be a case where the .profile is not used, e.g. when a non-interactive process is started I was not sure if .profile is used.

What do you mean with non-interactive?

If you login to your machine as sidadm the profile is invoked using one of the files you meant. So when you start your Engine the Environment is property set. If another process is spawned or forked from a running process it inherits / uses the same Environment.

Also, on one of my servers I have a .profile a .login and also a .cshrc file. Do I need to update all of these ?

the .profile is used by bash and ksh

The .cshrc is used by csh and it is included via source on every Shell Startup if not invoked with the -f Flag

the .login is also used by csh and it is included via source from the .cshrc

So if you want to support all shells you should update the .profile (bash and ksh) and one of .cshrc or .login for csh or tcsh

In my /etc/passwd the <sid>adm user is configured with /bin/csh shell, so I think this means my .cshrc will be used and not the .profile ? Is this correct ?

Yes correct, as described above!

Hope this helps

Cheers

Answers (1)

Answers (1)

tim_alsop
Active Contributor
0 Kudos

Thankyou. You have answered my question, and I am now clear on the best way to implement this.

Regarding my comment about non-interactive, I was thinking of a possible scenario where SAP AS is started during system reboot, and not by a person logging onto <sid>adm and running the startsap command. In that case the startup script would have to non-interactively logon as <sid>adm and then issue startsap command.

On Windows this would be something like:

runas /user=<sid>adm startsap

Thanks,

Tim