<?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 Re: Using function mopen to extract the log owner, while the log is still being created in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-function-mopen-to-extract-the-log-owner-while-the-log-is/m-p/858438#M339168</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Did you try it?&amp;nbsp; &amp;nbsp; It may depend on the OS.&amp;nbsp; I tried it on windows, using test code like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc printto log="Q:\junk\foologs\mylog5.log" new ;
run ;

%logs_get_files(logs_folder=Q:\junk\foologs, logs_from_dt=13NOV2022)

proc printto ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And it did not work.&amp;nbsp;&amp;nbsp;fid=mopen(did,file_name) ; returned 0 for the active log file which is still being written to.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But it's possible it is OS dependent.&amp;nbsp; Might be worth trying on linux. The success of this code probably depends on how the OS handles files that are currently open for writing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note you have an unrelated typo (extra semicolon) in your code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if datepart(created_dttm)&amp;gt;="&amp;amp;logs_from_dt"d then ;output;  *Do not want the semicolon after then ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you can't get it working, one option would be to wrap your code in a PROC PRINTTO block.&amp;nbsp; With that, when you close the PROC PRINTTO it will stop writing to the log file, and then you should be able to get the file's metadata.&amp;nbsp; So the below code is able to get the attributes of mylog6.log, because it is not active:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc printto log="Q:\junk\foologs\mylog6.log" new ;
run ;

*Main code here ;

data foo ;
  set sashelp.class ;
run ;

proc printto ;
run ;

%logs_get_files(logs_folder=Q:\junk\foologs, logs_from_dt=13NOV2022)&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 12 Feb 2023 12:43:41 GMT</pubDate>
    <dc:creator>Quentin</dc:creator>
    <dc:date>2023-02-12T12:43:41Z</dc:date>
    <item>
      <title>Using function mopen to extract the log owner, while the log is still being created</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-function-mopen-to-extract-the-log-owner-while-the-log-is/m-p/858436#M339167</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;when using the code below, can we get the information regarding the log owner (function mopen) even while the log is still being written ?&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let logs_folder=; &lt;BR /&gt;%let logs_from_dt=;&lt;BR /&gt;%macro logs_get_files(logs_folder=, logs_from_dt=);&lt;BR /&gt;data LOGS_FILES(keep=folder file_name file_size created_dttm owner);&lt;BR /&gt;length &lt;BR /&gt;Folder $200 &lt;BR /&gt;File_Name $100 &lt;BR /&gt;File_Size &lt;BR /&gt;Created_DTTM 8;&lt;BR /&gt;rc=filename('_dir_',"&amp;amp;logs_folder",'','encoding="utf-8"');&lt;BR /&gt;did=dopen('_dir_');&lt;BR /&gt;if (did lt 1) then do;&lt;BR /&gt;put "ERR" "OR: Unable to open &amp;amp;logs_folder as a directory.";&lt;BR /&gt;stop;&lt;BR /&gt;end;&lt;BR /&gt;do i=1 to dnum(did);&lt;BR /&gt;folder="&amp;amp;logs_folder";&lt;BR /&gt;file_name = scan(dread(did,i), -1, '\/');&lt;BR /&gt;File attributes;&lt;BR /&gt;fid=mopen(did,file_name);&lt;BR /&gt;type=ifc(fid &amp;gt; 0,'F','D');&lt;BR /&gt;if (type='F') then do;&lt;BR /&gt;ext = lowcase(scan(file_name,-1,'.'));&lt;BR /&gt;if ext='log' then do;&lt;BR /&gt;file_size = input(finfo(fid,'File Size (bytes)'),32.);&lt;BR /&gt;created_dttm = input(finfo(fid,'Create Time'),NLDATM30.); &lt;BR /&gt;owner= strip(finfo(fid,'Owner Name'));&lt;BR /&gt;if datepart(created_dttm)&amp;gt;="&amp;amp;logs_from_dt"d then ;output;&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;BR /&gt;fid=fclose(fid);&lt;BR /&gt;end;&lt;BR /&gt;did=dclose(did);&lt;BR /&gt;rc=filename('_dir_','');&lt;BR /&gt;format File_Size comma32. Created_DTTM datetime22.;&lt;BR /&gt;run;&lt;BR /&gt;%mend;&lt;BR /&gt;%logs_get_files(logs_folder=/sas/logs/, logs_from_dt=13NOV2022);&lt;/P&gt;</description>
      <pubDate>Sun, 12 Feb 2023 11:19:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-function-mopen-to-extract-the-log-owner-while-the-log-is/m-p/858436#M339167</guid>
      <dc:creator>J111</dc:creator>
      <dc:date>2023-02-12T11:19:29Z</dc:date>
    </item>
    <item>
      <title>Re: Using function mopen to extract the log owner, while the log is still being created</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-function-mopen-to-extract-the-log-owner-while-the-log-is/m-p/858438#M339168</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Did you try it?&amp;nbsp; &amp;nbsp; It may depend on the OS.&amp;nbsp; I tried it on windows, using test code like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc printto log="Q:\junk\foologs\mylog5.log" new ;
run ;

%logs_get_files(logs_folder=Q:\junk\foologs, logs_from_dt=13NOV2022)

proc printto ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And it did not work.&amp;nbsp;&amp;nbsp;fid=mopen(did,file_name) ; returned 0 for the active log file which is still being written to.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But it's possible it is OS dependent.&amp;nbsp; Might be worth trying on linux. The success of this code probably depends on how the OS handles files that are currently open for writing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note you have an unrelated typo (extra semicolon) in your code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if datepart(created_dttm)&amp;gt;="&amp;amp;logs_from_dt"d then ;output;  *Do not want the semicolon after then ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you can't get it working, one option would be to wrap your code in a PROC PRINTTO block.&amp;nbsp; With that, when you close the PROC PRINTTO it will stop writing to the log file, and then you should be able to get the file's metadata.&amp;nbsp; So the below code is able to get the attributes of mylog6.log, because it is not active:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc printto log="Q:\junk\foologs\mylog6.log" new ;
run ;

*Main code here ;

data foo ;
  set sashelp.class ;
run ;

proc printto ;
run ;

%logs_get_files(logs_folder=Q:\junk\foologs, logs_from_dt=13NOV2022)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 12 Feb 2023 12:43:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-function-mopen-to-extract-the-log-owner-while-the-log-is/m-p/858438#M339168</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-02-12T12:43:41Z</dc:date>
    </item>
    <item>
      <title>Re: Using function mopen to extract the log owner, while the log is still being created</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-function-mopen-to-extract-the-log-owner-while-the-log-is/m-p/858439#M339169</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We want to read 100 logs according to their owner, while some are still being created.&lt;/P&gt;
&lt;P&gt;What is the best way to do it ?&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Sun, 12 Feb 2023 13:07:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-function-mopen-to-extract-the-log-owner-while-the-log-is/m-p/858439#M339169</guid>
      <dc:creator>J111</dc:creator>
      <dc:date>2023-02-12T13:07:39Z</dc:date>
    </item>
    <item>
      <title>Re: Using function mopen to extract the log owner, while the log is still being created</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-function-mopen-to-extract-the-log-owner-while-the-log-is/m-p/858440#M339170</link>
      <description>&lt;P&gt;Shall try to clarify:-&lt;/P&gt;
&lt;P&gt;Lets say we have 2 owners of logs A &amp;amp; B&lt;/P&gt;
&lt;P&gt;If the owner is A we want to open the log and look into its details&lt;/P&gt;
&lt;P&gt;If the owner is B we want to skip this log and continue until we find anther log with owner A&lt;/P&gt;
&lt;P&gt;We want to know if the owner is A or B even if the log is still being created&lt;/P&gt;
&lt;P&gt;There are 100 logs in Linux Folder.&lt;/P&gt;
&lt;P&gt;Please advise&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 12 Feb 2023 13:15:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-function-mopen-to-extract-the-log-owner-while-the-log-is/m-p/858440#M339170</guid>
      <dc:creator>J111</dc:creator>
      <dc:date>2023-02-12T13:15:57Z</dc:date>
    </item>
    <item>
      <title>Re: Using function mopen to extract the log owner, while the log is still being created</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-function-mopen-to-extract-the-log-owner-while-the-log-is/m-p/858441#M339171</link>
      <description>&lt;P&gt;I think your current attempt makes sense.&amp;nbsp; What OS are your working on?&amp;nbsp; It didn't work for me on windows, but did you try it on linux?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If that code doesn't work, do you have XCMD enabled?&amp;nbsp; If so, then you can see if running LS or a similar OS command will be able to retrieve the file owner information of an active log file.&amp;nbsp; If it does, you can use filename pipe to execute the command and then parse the results.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To test, I would create a SAS job that SLEEPS for 30 minutes, and then open a command prompt and see if OS commands can tell you the owner of the log file that is actively being written to.&lt;/P&gt;</description>
      <pubDate>Sun, 12 Feb 2023 13:47:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-function-mopen-to-extract-the-log-owner-while-the-log-is/m-p/858441#M339171</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-02-12T13:47:51Z</dc:date>
    </item>
    <item>
      <title>Re: Using function mopen to extract the log owner, while the log is still being created</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-function-mopen-to-extract-the-log-owner-while-the-log-is/m-p/858442#M339172</link>
      <description>&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;One more detail - the program is running with EGUIDE&lt;/P&gt;</description>
      <pubDate>Sun, 12 Feb 2023 13:51:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-function-mopen-to-extract-the-log-owner-while-the-log-is/m-p/858442#M339172</guid>
      <dc:creator>J111</dc:creator>
      <dc:date>2023-02-12T13:51:32Z</dc:date>
    </item>
    <item>
      <title>Re: Using function mopen to extract the log owner, while the log is still being created</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-function-mopen-to-extract-the-log-owner-while-the-log-is/m-p/858446#M339174</link>
      <description>&lt;P&gt;Is the XCMD option active in your SAS session?&lt;/P&gt;
&lt;P&gt;If so it should be possible to see the owner of a file in Unix just use the normal ls command.&lt;/P&gt;
&lt;P&gt;The owner is the third value on the line and the filename is the last.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data log_files;
   length dummy $1 owner $30 filename $256 ;
   infile "ls /some/directory/*.log" pipe truncover ;
   input (2*dummy owner 5*dummy) (:) filename $256. ;
  drop dummy;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 12 Feb 2023 16:59:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-function-mopen-to-extract-the-log-owner-while-the-log-is/m-p/858446#M339174</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-02-12T16:59:24Z</dc:date>
    </item>
    <item>
      <title>Re: Using function mopen to extract the log owner, while the log is still being created</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-function-mopen-to-extract-the-log-owner-while-the-log-is/m-p/858447#M339175</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/386728"&gt;@J111&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Lets say we have 2 owners of logs A &amp;amp; B&lt;/P&gt;
&lt;P&gt;We want to know if the owner is A or B even if the log is still being created&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;"If the log is still being created" points me to process id system tools and/or metadata, not open the file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I question the utility of attempting to read a file that is still being created. That means the content is changing as you look at it. So, just what to you want to find in these open logs?&lt;/P&gt;</description>
      <pubDate>Sun, 12 Feb 2023 17:00:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-function-mopen-to-extract-the-log-owner-while-the-log-is/m-p/858447#M339175</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-02-12T17:00:10Z</dc:date>
    </item>
    <item>
      <title>Re: Using function mopen to extract the log owner, while the log is still being created</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-function-mopen-to-extract-the-log-owner-while-the-log-is/m-p/858463#M339181</link>
      <description>&lt;P&gt;I suspect it's a Windows machine since Unix wouldn't care that the files are in use.&lt;/P&gt;
&lt;P&gt;Switch /q adds the owner to the command.&lt;BR /&gt;How the line is parsed will depend on your local Windows settings.&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;data log_files;
  ...
  infile "dir &amp;amp;path /q" pipe truncover ;
  ...
run;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Feb 2023 01:49:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-function-mopen-to-extract-the-log-owner-while-the-log-is/m-p/858463#M339181</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2023-02-13T01:49:08Z</dc:date>
    </item>
    <item>
      <title>Re: Using function mopen to extract the log owner, while the log is still being created</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-function-mopen-to-extract-the-log-owner-while-the-log-is/m-p/858474#M339188</link>
      <description>&lt;P&gt;Many thanks for all the replies.&lt;/P&gt;
&lt;P&gt;1.&lt;/P&gt;
&lt;P&gt;ERROR: Insufficient authorization to access PIPE.&lt;/P&gt;
&lt;P&gt;2.&lt;/P&gt;
&lt;P&gt;We are looking into ERROR lines in the log, during the next step&lt;/P&gt;
&lt;P&gt;3.&lt;/P&gt;
&lt;P&gt;We shall try to run the program while&amp;nbsp; a log is being created&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Feb 2023 05:52:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-function-mopen-to-extract-the-log-owner-while-the-log-is/m-p/858474#M339188</guid>
      <dc:creator>J111</dc:creator>
      <dc:date>2023-02-13T05:52:41Z</dc:date>
    </item>
    <item>
      <title>Re: Using function mopen to extract the log owner, while the log is still being created</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-function-mopen-to-extract-the-log-owner-while-the-log-is/m-p/858503#M339207</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/386728"&gt;@J111&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Many thanks for all the replies.&lt;/P&gt;
&lt;P&gt;1.&lt;/P&gt;
&lt;P&gt;ERROR: Insufficient authorization to access PIPE.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This means you don't have the system option XCMD turned on.&amp;nbsp; In order to execute native OS commands from SAS, your admin will need to turn on XCMD.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Feb 2023 13:31:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-function-mopen-to-extract-the-log-owner-while-the-log-is/m-p/858503#M339207</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-02-13T13:31:42Z</dc:date>
    </item>
  </channel>
</rss>

