I DON'T actually need a response since I have a solution but the education would be nice.
Some history:
We've recently converted from alpha login ID's in the LDAP world to something called workday ID's(not my idea!). What this meant for us Linux admins was we had change everyone's alpha ID they'd used for years to a numeric ID. Not a big deal with the exception of a particular command we use to list jobs on the cluster. If I execute:
Code:
bjobs -u all -m C7CRA
I now get the following:
Code:
JOBID USER STAT QUEUE FROM_HOST EXEC_HOST JOB_NAME SUBMIT_TIME
452790 257738 RUN crash_para t70cra110 16*t70c7n22 *art_ODB_5 Nov 27 10:00
16*t70c7n222
16*t70c7n223
16*t70c7n224
16*t70c7n227
16*t70c7n226
16*t70c7n228
16*t70c7n225
452803 257738 RUN crash_para t70cra110 16*t70c7n22 *L_Corr_03 Nov 27 10:55
16*t70c7n230
16*t70c7n231
16*t70c7n234
16*t70c7n236
16*t70c7n233
16*t70c7n232
16*t70c7n235
452878 257738 RUN crash_para t70cra110 16*t70c7n25 *L_Corr_04 Nov 27 17:01
16*t70c7n261
16*t70c7n262
16*t70c7n263
16*t70c7n264
16*t70c7n258
16*t70c7n260
16*t70c7n259
The second field of the job ID line is the user's name now and we have been using ypcat to figure out who's who. A real pain, so I wrote a script (bjobs.sh) to replace the workday numeric ID with the 5th field from the ypcat passwd output.
Script:
Code:
#!/bin/bash
echo "JOBID USER STAT QUEUE FROM_HOST EXEC_HOST JOB_NAME SUBMIT_TIME"
for JOBID in `bjobs $* | grep RUN | awk '{print $1}'`
do
USERID=`bjobs ${JOBID} | grep RUN | awk '{print $2}'`
USERNAME=`ypcat passwd | grep ${USERID} | cut -d: -f5`
bjobs ${JOBID} | grep -v STAT | sed "s/${USERID}/${USERNAME}/"
done
Executed as:
Code:
bjobs.sh -u all -m C76CRA
While this works just fine I though I'd put this up here to see if anyone had a better way of doing this. Maybe a one line "bjobs -u all -m C7CRA" with awk and/or sed to grab that second field of the jobid line and replace it as the script does using the variable it gets from the ypcat passwd output. I tried various methods, got frustrated and simply went with what I knew would work. Thanks in advance for anyone willing to chime in.
---------- Post updated at 11:02 AM ---------- Previous update was at 10:57 AM ----------
So what we're getting now when using the script is:
Code:
JOBID USER STAT QUEUE FROM_HOST EXEC_HOST JOB_NAME SUBMIT_TIME
452790 John Doe VPD5 RUN crash_para t70cra110 16*t70c7n22 *art_ODB_5 Nov 27 10:00
16*t70c7n222
16*t70c7n223
16*t70c7n224
16*t70c7n227
16*t70c7n226
16*t70c7n228
16*t70c7n225
452803 John Doe VPD5 RUN crash_para t70cra110 16*t70c7n22 *L_Corr_03 Nov 27 10:55
16*t70c7n230
16*t70c7n231
16*t70c7n234
16*t70c7n236
16*t70c7n233
16*t70c7n232
16*t70c7n235
452878 John Doe VPD5 RUN crash_para t70cra110 16*t70c7n25 *L_Corr_04 Nov 27 17:01
16*t70c7n261
16*t70c7n262
16*t70c7n263
16*t70c7n264
16*t70c7n258
16*t70c7n260
16*t70c7n259
Thanks for the response Scrutinizer. The line formatting was a good idea as it gave me something to go on with the other jobs like PEND and EXIT since they format a bit differently. I can now actually arrange the total output into something formatted better than the default.
I ended up using ypcat rather than getent since getent won't return user ID's that are all numeric. After some tinkering, getent proved to only return ID's that have at least one alpha character in them.
Hello RudiC,
Thanks for the response. The only issue with the single line command is it only works on the NIS master with the passwd file at /var/yp/files/passwd. All the other nodes in the cluster have the most basic passwd file. Which is why I felt forced to ypcat the passwd file for the 'real name'.
I had originally tried to assign a variable the value from ypcat on the awk command line but failed.
Hello :)
new to bash not to programming.
I have an on-going need to change the owning group on sets of files and directories from the one they were created with or changed to on update to the one they need to have going forward.
find {target_root} -group wrong_group
gets me a newline... (4 Replies)
I am using UNIX to create a script on our system. I have setup my commands to append their output to an outage file. However, some of the commands return no output and so I would like something to take their place.
What I need
The following command is placed at the prompt:
TICLI... (4 Replies)
Hi Guys,
I like to output every command executed in the script to a file.
I have tried set -x which does the same.
But it is not giving the logs of the child script which is being called from my script.
Is there any parameters in the Set command or someother way where i can see the log... (2 Replies)
I ran the following command.
cat abc.c > abc.c
I got message the following message from command cat:
cat: abc.c : input file is same as the output file
How the command came to know of the destination file name as the command is sending output to standard file. (3 Replies)
Hi Experts,
I am very much new to linux scripting, I am currently working on reducing my manual work and hence writing a script to automate few task.
I am running below command to snmpwalk the router..
snmpwalk -v 3 -u WANDL_SU -a MD5 -A vfipmpls -x DES -X VfIpMpLs -l authPriv... (19 Replies)
HI Guys,
I hope you are well. I am trying to write a script that gets executed every time i open a shell (cshell). I have two questions about that
1) I need to enter these commands
$ echo $DISPLAY
$ setenv $DISPLAY output_of_echo_$display_command
How can i write a... (2 Replies)
Hey, guys!
Trying to research this is such a pain since the read command itself is a common word. Try searching "unix OR linux read command examples" or using the command substitution keyword. :eek:
So, I wanted to use a command statement similar to the following.
This is kinda taken... (2 Replies)
Is there a way to repeat the output of the last command for filtering without running the command again? All I could think of was to copy all the data to a text file and process it that way, is there another way? Like say I want to grep server.server.lan from a dtrace that was pages long after I... (5 Replies)
Hi folks,
Please advise which command/command line shall I run;
1) to display the command and its output on console
2) simultaneous to save the command and its output on a file
I tried tee command as follows;
$ ps aux | grep mysql | tee /path/to/output.txt
It displayed the... (7 Replies)
Hi,
I am triying to make sure that there exists only one file with the pattern abc* in path /path/. This directory is having many huge files. If there is only one file then I have to take its complete name only to use furter in my script.
I am planning to do like this:
if ; then... (2 Replies)