Skip to content

Instantly share code, notes, and snippets.

@forstie
Last active January 25, 2024 22:34
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save forstie/80001ef9cbfad0112eb8a61fe3da4ac9 to your computer and use it in GitHub Desktop.
Save forstie/80001ef9cbfad0112eb8a61fe3da4ac9 to your computer and use it in GitHub Desktop.
Use SQL's NETSTAT and ACTIVE_JOB_INFO services to identify and explore active 5250 sessions.
--
-- description: Find active Telnet or Interactive 5250 sessions
--
-- resource: ibm.biz/WellDefinedIBMiPorts
--
select remote_address, remote_port, authorization_name as user_name, job_name
from qsys2.netstat_job_info n
where local_port in (23,992) and job_type = 'INTERACTIVE';
--
-- description: Find Interactive jobs
--
select * from table(qsys2.active_job_info(
subsystem_list_filter => 'QINTER',
detailed_info => 'ALL')) b where job_type = 'INT';
--
-- description: Join them together (secret sauce)
--
with active5250(remote_address, remote_port, user_name, job_name) as (
select remote_address, remote_port, authorization_name as user_name, job_name
from qsys2.netstat_job_info n
where local_port in (23,992) and job_type = 'INTERACTIVE'
)
select remote_address, remote_port, user_name, a.job_name,
sql_statement_status, sql_statement_text, b.* from active5250 a inner join
table(qsys2.active_job_info(subsystem_list_filter => 'QINTER',
detailed_info => 'ALL')) b
on a.job_name = b.job_name where job_type = 'INT';
@chrjorgensen
Copy link

Nice tool - maybe you should include port 992 for 5250 over SSL... hopefully there would be more connections on this port than on port 23...! :-)

@forstie
Copy link
Author

forstie commented Jun 30, 2019

Great point... updated.
Thanks Christian

@mmayer625
Copy link

Really nice @ V7R2 ... errors out at V7R1. No big deal. Copyu and pasted in ACS SQL and looks great!

@forstie
Copy link
Author

forstie commented Oct 29, 2019

Yes, the => named parameter invocation of a UDTF is support that was added with IBM i 7.2.

@mmayer625
Copy link

mmayer625 commented Oct 29, 2019 via email

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