<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic ArcGIS Server on Linux python unable to change file permissions. in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/arcgis-server-on-linux-python-unable-to-change/m-p/272971#M21106</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I've got a python program that needs to write to a log file. Usually that log file exists. If it doesnt, it needs to be created. And if its created, it needs to be group-writeable, because there are other programs that operate under other users that will need to write to it.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This all has worked fine using the python installed with ArcGIS Desktop 10.0 on Windows, but using 10.1 Server on Linux, as I now need to do, the group permissions are not getting set correctly, and using shutil to try to set them is failing.&amp;nbsp; And it works correctly using the standard python (version 2.6.6) installed on my workstation&amp;nbsp; (RHEL 6.2). So I'm not sure if the issue is python 2.6 vs 2.7, or if there are additional restrictions on the ArcGIS Server python. Here's what I'm talking about:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;template.log is simply an empty file with both user and group permissions set to read-write:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;-rw-rw-r--. 1 dan users&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0 Jun&amp;nbsp; 21 13:32 template.log&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Simple code to illustrate:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import shutil

template = 'template.log'
newfile = '2012-172.log'

shutil.copy(template, newfile)
shutil.copymode(template, newfile)&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Running the above in non-ESRI python 2.6.6:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;$ python
Python 2.6.6 (r266:84292, Jun 18 2012, 09:57:52) 
[GCC 4.4.6 20110731 (Red Hat 4.4.6-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
&amp;gt;&amp;gt;&amp;gt; import shutil
&amp;gt;&amp;gt;&amp;gt; template = 'template.log'
&amp;gt;&amp;gt;&amp;gt; newfile = '2012-172.log'
&amp;gt;&amp;gt;&amp;gt; shutil.copy(template, newfile)
&amp;gt;&amp;gt;&amp;gt; quit()
$
$ ls -l template.log 2012-172.log
-rw-r--r--. 1 ags users 0 Jun 21 13:33 2012-172.log
-rw-r--r--. 1 dan users 0 Jun 21 13:32 template.log&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Just what I need. And I didnt have to bother with the shutil.copymode as the above maintains the source files' permissions.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;But if I use ArcGIS Server's (10.1) python: &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;$ /home/ags/arcgis/server/tools/python
Python 2.7.2 (default, Jun 12 2011, 14:24:46) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
&amp;gt;&amp;gt;&amp;gt; import shutil
&amp;gt;&amp;gt;&amp;gt; template = 'template.log'
&amp;gt;&amp;gt;&amp;gt; newfile = '2012-172.log'
&amp;gt;&amp;gt;&amp;gt; shutil.copy(template, newfile)
&amp;gt;&amp;gt;&amp;gt; 
[1]+&amp;nbsp; Stopped&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /home/ags/arcgis/server/tools/python
$ ls -l template.log 2012-172.log
-rw-------. 1 ags users 0 Jun 21 13:37 2012-172.log
-rw-r--r--. 1 dan users 0 Jun 21 13:32 template.log
$ fg

&amp;gt;&amp;gt;&amp;gt; shutil.copymode(template, newfile)
&amp;gt;&amp;gt;&amp;gt; quit()
$
$ ls -l template.log 2012-172.log
-rw-------. 1 ags users 0 Jun 21 13:37 2012-172.log
-rw-r--r--. 1 dan users 0 Jun 21 13:32 template.log&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Note that the shutil.copymode isnt able to do anything, nor does it complain.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've also done this with template.log owned by user ags instead of dan; same problem.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks much for any clues or suggestions.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 21 Jun 2012 17:00:21 GMT</pubDate>
    <dc:creator>DanSlayback</dc:creator>
    <dc:date>2012-06-21T17:00:21Z</dc:date>
    <item>
      <title>ArcGIS Server on Linux python unable to change file permissions.</title>
      <link>https://community.esri.com/t5/python-questions/arcgis-server-on-linux-python-unable-to-change/m-p/272971#M21106</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I've got a python program that needs to write to a log file. Usually that log file exists. If it doesnt, it needs to be created. And if its created, it needs to be group-writeable, because there are other programs that operate under other users that will need to write to it.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This all has worked fine using the python installed with ArcGIS Desktop 10.0 on Windows, but using 10.1 Server on Linux, as I now need to do, the group permissions are not getting set correctly, and using shutil to try to set them is failing.&amp;nbsp; And it works correctly using the standard python (version 2.6.6) installed on my workstation&amp;nbsp; (RHEL 6.2). So I'm not sure if the issue is python 2.6 vs 2.7, or if there are additional restrictions on the ArcGIS Server python. Here's what I'm talking about:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;template.log is simply an empty file with both user and group permissions set to read-write:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;-rw-rw-r--. 1 dan users&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0 Jun&amp;nbsp; 21 13:32 template.log&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Simple code to illustrate:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import shutil

template = 'template.log'
newfile = '2012-172.log'

shutil.copy(template, newfile)
shutil.copymode(template, newfile)&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Running the above in non-ESRI python 2.6.6:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;$ python
Python 2.6.6 (r266:84292, Jun 18 2012, 09:57:52) 
[GCC 4.4.6 20110731 (Red Hat 4.4.6-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
&amp;gt;&amp;gt;&amp;gt; import shutil
&amp;gt;&amp;gt;&amp;gt; template = 'template.log'
&amp;gt;&amp;gt;&amp;gt; newfile = '2012-172.log'
&amp;gt;&amp;gt;&amp;gt; shutil.copy(template, newfile)
&amp;gt;&amp;gt;&amp;gt; quit()
$
$ ls -l template.log 2012-172.log
-rw-r--r--. 1 ags users 0 Jun 21 13:33 2012-172.log
-rw-r--r--. 1 dan users 0 Jun 21 13:32 template.log&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Just what I need. And I didnt have to bother with the shutil.copymode as the above maintains the source files' permissions.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;But if I use ArcGIS Server's (10.1) python: &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;$ /home/ags/arcgis/server/tools/python
Python 2.7.2 (default, Jun 12 2011, 14:24:46) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
&amp;gt;&amp;gt;&amp;gt; import shutil
&amp;gt;&amp;gt;&amp;gt; template = 'template.log'
&amp;gt;&amp;gt;&amp;gt; newfile = '2012-172.log'
&amp;gt;&amp;gt;&amp;gt; shutil.copy(template, newfile)
&amp;gt;&amp;gt;&amp;gt; 
[1]+&amp;nbsp; Stopped&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /home/ags/arcgis/server/tools/python
$ ls -l template.log 2012-172.log
-rw-------. 1 ags users 0 Jun 21 13:37 2012-172.log
-rw-r--r--. 1 dan users 0 Jun 21 13:32 template.log
$ fg

&amp;gt;&amp;gt;&amp;gt; shutil.copymode(template, newfile)
&amp;gt;&amp;gt;&amp;gt; quit()
$
$ ls -l template.log 2012-172.log
-rw-------. 1 ags users 0 Jun 21 13:37 2012-172.log
-rw-r--r--. 1 dan users 0 Jun 21 13:32 template.log&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Note that the shutil.copymode isnt able to do anything, nor does it complain.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've also done this with template.log owned by user ags instead of dan; same problem.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks much for any clues or suggestions.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Jun 2012 17:00:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcgis-server-on-linux-python-unable-to-change/m-p/272971#M21106</guid>
      <dc:creator>DanSlayback</dc:creator>
      <dc:date>2012-06-21T17:00:21Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS Server on Linux python unable to change file permissions.</title>
      <link>https://community.esri.com/t5/python-questions/arcgis-server-on-linux-python-unable-to-change/m-p/272972#M21107</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Could you put in a command like:&lt;/SPAN&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;os.system('chmod go+r 2012-172.log')&lt;/PRE&gt;&lt;SPAN&gt;to fix the permissions?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Jun 2012 19:36:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcgis-server-on-linux-python-unable-to-change/m-p/272972#M21107</guid>
      <dc:creator>BruceNielsen</dc:creator>
      <dc:date>2012-06-21T19:36:21Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS Server on Linux python unable to change file permissions.</title>
      <link>https://community.esri.com/t5/python-questions/arcgis-server-on-linux-python-unable-to-change/m-p/272973#M21108</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;i was actually trying to avoid using linux commands, because I wanted the code to work under either Windows or Linux. although clearly a simple check on the os and an if statement could solve that problem.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;However, even this does not work using ESRI's installed python, and yet works with the OS-installed python! Quite bizarre:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
$ /home/ags/arcgis/server/tools/python
Python 2.7.2 (default, Jun 12 2011, 14:24:46) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
&amp;gt;&amp;gt;&amp;gt; import os
&amp;gt;&amp;gt;&amp;gt; os.system('chmod g+w 2012-172.log')
os.system('chmod g+w 2012-172.log')
File not found

9009
&amp;gt;&amp;gt;&amp;gt; ^Z
[1]+&amp;nbsp; Stopped&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /home/ags/arcgis/server/tools/python
$ ls -l 2012-172.log 
-rw-------. 1 ags users 0 Jun 25 08:00 2012-172.log
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;And giving it the full path does not help.&amp;nbsp; Whereas, for system-installed python:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;$ python
Python 2.6.6 (r266:84292, Jun 18 2012, 09:57:52) 
[GCC 4.4.6 20110731 (Red Hat 4.4.6-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
&amp;gt;&amp;gt;&amp;gt; import os
&amp;gt;&amp;gt;&amp;gt; os.system('chmod g+w 2012-172.log')
0
&amp;gt;&amp;gt;&amp;gt; 
[1]+&amp;nbsp; Stopped&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; python
$ ls -l 2012-172.log 
-rw--w----. 1 ags users 0 Jun 25 08:00 2012-172.log&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;is this possibly correct, or is this likely a bug?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 13:20:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcgis-server-on-linux-python-unable-to-change/m-p/272973#M21108</guid>
      <dc:creator>DanSlayback</dc:creator>
      <dc:date>2021-12-11T13:20:05Z</dc:date>
    </item>
  </channel>
</rss>

