Aug 25 2016
List AS400 Profiles JOBQ
I want to do a bit of cleanup because users jobs are running in all sort of queues. JOBQ are defined within JOBD (Job Description) that are assigned to user profiles. I can get the job descriptions easily with the WRKUSRPRF command but getting all job queues at once is trickier.
If you’re familiar with PASE, it’s easy to get the job done and even assign new JOBD to profiles based on their current value.
Connect to PASE environment either running ‘CALL QP2TERM’ or SSH if the service is up and running.
Copy the following shell code into a file (let’s call it listJobq.sh) in the IFS, on your home directory for instance, make it executable
chmod +x listJobq.sh
and run:
./listJobq.sh
#!/QOpenSys/usr/bin/ksh IFS=' ' # Uncomment or run once and for all from a 5250 session # Make sure the ADMIN library exists #system "DSPUSRPRF USRPRF(*ALL) OUTPUT(*OUTFILE) OUTFILE(ADMIN/USERLIST)" printf "%11s%11s%11s\n" "USRPRF" "JOBD" "JOBQ" for i in $(db2 "select upuprf,upjbds from ADMIN.USERLIST" | \ sed -e '1,3 d' -e '/^$/ d' | sed -e '$ d'); do unset IFS set -A user $i jobq=`system -i "DSPJOBD JOBD(${user[1]})" | awk '/^ Fi/ {print $NF;exit;}'` printf "%11s%11s%11s\n" "${user[0]}" "${user[1]}" "$jobq" done
Here’s the output:
USRPRF JOBD JOBQ ABERTRAND DEFAULT QBATCH GBOUBOURS DEFAULT QBATCH IBURNET IT QPGMR PBUISSON DEFAULT QBATCH PMARTIN DEFAULT QBATCH ... ... ...
The system may return a “db2: cannot execute” or “/usr/bin/db2: Permission denied” message. Create a symbolic link like this:
ln -s /QOpenSys/usr/bin/qsh /QOpenSys/usr/bin/db2
The reason lies in this explanation.
The downside is the “system” command slowness. -i speeds things up a bit but it’s still not quick enough. If you have installed the OPS (Open Source) package from IBM along with matching PTF and bash, you can try this optimized version with hash tables in bash.
It stores jobd/jobq in a hash table to act as a cache since a jobd definition always returns the same job. If a lot of users have the same JOBD, it can be very efficient (35 times quicker in my case).
#!/usr/bin/bash IFS=' ' declare -A JOBQ # Uncomment or run once and for all from a 5250 session # Make sure the ADMIN library exists #system "DSPUSRPRF USRPRF(*ALL) OUTPUT(*OUTFILE) OUTFILE(ADMIN/USERLIST)" printf "%11s%11s%11s\n" "USRPRF" "JOBD" "JOBQ" for i in $(db2 "select upuprf,upjbds from ADMIN.USERLIST" | \ sed -e '1,3 d' -e '/^$/ d' | sed -e '$ d'); do unset IFS # Sets username and jobd in user[0] and user[1] user=($i) # Add jobq to hash table if [ -z ${JOBQ[${user[1]}]} ]; then jobq=`system -i "DSPJOBD JOBD(${user[1]})" | awk '/^ Fi/ {print $NF;exit;}'` JOBQ[${user[1]}]=$jobq fi printf "%11s%11s%11s\n" "${user[0]}" "${user[1]}" "${JOBQ[${user[1]}]}" done