python and ubuntu's environment

Tung Thanh con500thoi at
Wed Jul 24 12:37:40 UTC 2013

Many thank!

I have already checked and here is difference between when I run in command line and form web processing service (WPS)

I stast tomcat by using: 
 sudo -s mywps bash

and everything (insluding folder and environment locally in side /hom/mywps )
I and do python in command line 
the results as bellow:

I run tomcat by request url from curl and stringger python code

in Python code I put 
import os
import sys

print os.environ

and the log file was printed 

'mywps', 'LANG': 'en_US.UTF-8', 
'SUDO_GID': '1001', 'SHELL': '/bin/bash', 
'SUDO_COMMAND': '/bin/bash', 
'SHLVL': '0', 'SUDO_UID': '1001', 'TERM': 'xterm',
 'CATALINA_BASE': '/home/mywps/tomcatInstances/tomcatwps', 
 'PATH': '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', 
 'PWD': '/home/mywps/tomcatInstances/tomcatwps/bin', 
 'LOGNAME': 'mywps', 'USER': 'mywps', 'HOME': '/home/mywps', 
 'MAIL': '/var/mail/mywps', 'CATALINA_HOME': '/home/mywps/tomcat', 
 'SUDO_USER': 'mywps', 'CATALINA_OPTS': '-Xms256m -Xmx512m'}


$ python
Python 2.6.5 (r265:79063, Feb 28 2011, 21:55:45)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-50)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> print os.environ
{'HOMEDISC': '/home/mywps', 'LESSOPEN': '|/usr/bin/ %s',
 'SSH_CLIENT': 'my IP 64615 22', 'CVS_RSH': 'ssh', 'LOGNAME': 'mywps', 'USER': 'mywps', 
 'INPUTRC': '/etc/inputrc', 'HOME': '/home/ISIS/mywps', 
 'PATH': '/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/home/ISIS/mywps/bin:/home/ISIS/mywps/local/bin:/home/mywps/local/grass-6.4.1/bin:/home/mywps/local/grass-6.4.1/scripts:.',
 'LD_LIBRARY_PATH': ':/home/mywps/local/grass-6.4.1/lib:/home/intel-comp/intel/Compiler/11.0/081/lib/intel64/', 
 'GISBASE': '/home/mywps/local/grass-6.4.1', 'LANG': 'en_US.UTF-8', 'TERM': 'xterm', 
 'SHELL': '/bin/bash', 
 'SHLVL': '1', 'G_BROKEN_FILENAMES': '1', 'HISTSIZE': '1000', 
 'PYTHONPATH': '/home/mywps/local/grass-6.4.1/etc/python:/home/ISIS/mywps/grassdata/scripts', 
 'KRB5CCNAME': 'FILE:/tmp/krb5cc_33179_sqC5DF', 'GISRC': '/home/ISIS/mywps/grassdata/.grass64', 
 'TOMIB': '/home/mywps/tomcatInstances/tomcatB', 'TOMIA': '/home/mywps/tomcatInstances/tomcatA', 
 '_': '/usr/bin/python26', 'GISDBASE': '/home/ISIS/mywps/grassdata', 'SSH_CONNECTION': 'my ip login 64615 ip login  22', 'SSH_TTY': '/dev/pts/3', 
 'OLDPWD': '/home/ISIS/mywps', 'HOSTNAME': '', 'PWD': '/home/ISIS/mywps/rainEtrap', 'MAIL': '/var/spool/mail/mywps',
 'LS_COLORS': 'no=00:fi=00:di=00;34:ln=00;36:pi=40;33:so=00;35:bd=40;33;01:cd=40;33;01:or=01;05;37;41:mi=01;05;37;41:ex=00;32:*.cmd=00;32:*.exe=00;32:*.com=00;32:*.btm=00;32:*.bat=00;32:*.sh=00;32:*.csh=00;32:*.tar=00;31:*.tgz=00;31:*.arj=00;31:*.taz=00;31:*.lzh=00;31:*.zip=00;31:*.z=00;31:*.Z=00;31:*.gz=00;31:*.bz2=00;31:*.bz=00;31:*.tz=00;31:*.rpm=00;31:*.cpio=00;31:*.jpg=00;35:*.gif=00;35:*.bmp=00;35:*.xbm=00;35:*.xpm=00;35:*.png=00;35:*.tif=00;35:'}

 From: Patrick Asselman <iceblink at>
To: ubuntu-users at 
Sent: Wednesday, July 24, 2013 9:51 AM
Subject: Re: python and ubuntu's environment

On 2013-07-23 17:48, Tung Thanh wrote:
> Thank you for your very useful and fast answer
> there is command or somehow that I can change my our username mywps
> to be able for calling wps web services or there is the command line
> how to check for which username and permission were pointed when I 
> run
> web service from outside or locally
> I was sucked for more than one week,
> Many Thanks
> T.X.Tung

There is the command "sudo" that allows you to do 1 single command as 
another user, for instance "sudo -u wps ls" will perform the command 
"ls" as user wps.

There is also the command "su" that allows you to do everythgin as 
another user, i.e. "su wps".

You may need to add yourself to the /etc/sudoers file to obtain 
permission for impersonating another user.

But frankly I think the best way to solve this is to debug via Python 
itself, becaus that will show you exactly what is happening within the 
Python environment.

Best regards,
Patrick Asselman

ubuntu-users mailing list
ubuntu-users at
Modify settings or unsubscribe at:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the ubuntu-users mailing list