- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi there,
I have been getting this error when reading a list of log files. Some of them can be 'hot' running some house cleaning at the background.
Instead of bombing out each time, is there a way to know which one is currently being written to so that I can skip reading it altogether? Or any other approach as long as SAS EG won't error out.
ERROR: Resource is write-locked by another user. File=/somepath/abc_yymmdd.log. System Error Code = 11.
ERROR: File is in use, /somepath/abc_yymmdd.log.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
As much as I remember SAS adds a suffix .lck to locked files, any how I'm not sure is it done to log files too. It may depend on OS.
Check the directory where logs are kept and see if there are files with suffix .log.lck
or .loglck or alike.
Alternatively, if you need read only the log (not writing to it) maybe you can open it
with the READONLY option.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Log files do not have an additional .lck extension when being written to, and, at least on UNIX, SAS does not have the file locked while it is used, as you can always read it while the program is still running.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I assume that you are reading a number of files in a single data step, and that the whole thing crashes when one of the files are not available.
I think the way to go is to use the FOPEN or MOPEN function. That should just return a zero if the file is not available for reading, in which case you can use the SYSRC() and SYSMSG() functions to see what went wrong.
For instance, if you are reading all the .log files from a specific directory, it can be done something like this:
filename logdir 'c:\saslogs';
data loglines;
dir_id=dopen('logdir');
if dir_id=0 then do;
msg=sysmsg();
put msg=;
stop;
end;
do _N_=1 to dnum(dir_id);
filename=dread(dir_id,_N_);
if upcase(scan(filename,-1,'.'))='LOG' then do;
file_id=mopen(dir_id,_N_);
if file_id=0 then do;
msg=sysmsg();
put filename= msg=;
end;
else do;
/* code to read the file, one option is to use FREAD and FGET: */
do line_no=1 by 1 while(fread(file_id)=0);
length line $200;
rc=fget(file_id,line);
output;
end;
rc=fclose(file_id);
end;
end;
end;
rc=dclose(dir_id);
drop dir_id file_id rc;
stop;
run;
Of course, you may want to replace the OUTPUT statement with some more advanced processing of the log line, such as looking for errors or warnings, and only outputting those.