Aug 25 2016

List AS400 User Profiles and their Default JOBQ

Published by at 10:31 pm under AS400

I want to do a bit of cleanup on our main IBM i because users jobs are running in all sort of queues. Most users have a dedicated JOBD and JOBQ, which is wrong in my humble opinion. A user’s JOBQ is defined within the user’s JOBD (Job Description). A JOBD references a JOBQ and can be assigned to as many users as you wish. The first thing I would need is a list of everybody’s default JOBQ.

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 JOBDs to profiles based on their current value.


JOBD/JOBQ List by User Profile

Connect to PASE environment either running ‘CALL QP2TERM’ or SSH if the service is set 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='
'
# Make sure the ADMIN library exists or use another
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

 
This generates a list of USRPRF / JOBD / JOBQ. Most profiles now use the DEFAULT JOBD which sends users’ jobs to the QBATCH JOBQ if not defined otherwise.

AS400 users profile default JOBQ list


The system may return a “db2: cannot execute” or “/usr/bin/db2: Permission denied” message. In this case, create a symbolic link like this:
ln -s /QOpenSys/usr/bin/qsh /QOpenSys/usr/bin/db2
The reason lies in this explanation.


Bash Script Optimisation on PASE

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 optimised version with hash tables in bash. Opensource packages can now be managed from the IBM i ACS user interface, which is very handy.
It stores jobd/jobq in a hash table that acts 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). This is a trick to get better performance for shell scripts on IBM i that are still running slow compared to x86 servers.
 

#!/usr/bin/bash

IFS='
'
declare -A JOBQ

# Make sure the ADMIN library exists or use another
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

No responses yet

Trackback URI | Comments RSS

Leave a Reply