Skip to content

Instantly share code, notes, and snippets.

@forstie
Last active October 3, 2020 23:40
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save forstie/eb619063f46284365901dc88033bc6ce to your computer and use it in GitHub Desktop.
Save forstie/eb619063f46284365901dc88033bc6ce to your computer and use it in GitHub Desktop.
This example picks on the IFS stream files found within and under the /tmp directory. How much gunk has been accumulated under /tmp and what can you do to manage it? A bit of SQL to the rescue. The IFS_OBJECT_STATISTICS() UDTF returns many elements of data for you to leverage for improved management of the IFS.
--
-- Reference material: https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_74/rzajq/rzajqudfifsobjstat.htm
--
--
-- How much space is used by stream files from /tmp (and subdirs) that haven't been used in 6 months
--
select varchar_format(sum(data_size),'999G999G999G999G999G999G999') tmp_size
from table (
qsys2.ifs_object_statistics(start_path_name => '/tmp',
subtree_directories => 'YES',
OBJECT_TYPE_LIST => '*ALLSTMF')
) where last_used_timestamp < current timestamp - 6 months ;
--
-- Remove stream files from /tmp (and subdirs) that haven't been used in 6 months
--
begin
declare not_found condition for '02000';
declare at_end integer default 0;
declare local_path dbclob(16m);
declare v_cmdstmt clob(16m) for sbcs data;
declare ifs_cursor cursor for
select path_name
from table (
qsys2.ifs_object_statistics(start_path_name => '/tmp',
subtree_directories => 'YES',
OBJECT_TYPE_LIST => '*ALLSTMF')
) where last_used_timestamp < current timestamp - 6 months;
declare continue handler for not_found set at_end = 1;
open ifs_cursor;
fetch from ifs_cursor into local_path;
while (at_end = 0) do
set v_cmdstmt = 'QSYS/RMVLNK OBJLNK(''' concat local_path concat ''')';
call qsys2.qcmdexc(v_cmdstmt);
fetch from ifs_cursor into local_path;
end while;
close ifs_cursor;
end;
--
-- How much space is used by stream files from /tmp (and subdirs) that haven't been used in 6 months
--
select varchar_format(sum(data_size),'999G999G999G999G999G999G999') tmp_size
from table (
qsys2.ifs_object_statistics(start_path_name => '/tmp',
subtree_directories => 'YES',
OBJECT_TYPE_LIST => '*ALLSTMF')
) where last_used_timestamp < current timestamp - 6 months ;
@RainerRoss
Copy link

Nice Tool Scott!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment