At run time Without knowing job name how to check the job running in specific user "ABCD" ,If the running job duplicate more then 10 then script it self send alert message to the users with the process ID name so that will kill the processed to avoid hung issue ,tried below script please check and let me know if any comments
1)Not able to add line to check job running duplicate more then 10 times
ps -fu ABCD | awk '{print $1 $2,$8}' | \
while read pid ppid
do
then
mail -s "Please kill the process " "kalia@gmail.com"
fi
done
We cant reply if you spend your time modifying your code, our posts risk beeing off topic you already modifies 3 times - I started to reply to the previous and found the code changed again making my reply completely ununderstandable
Am attaching sample input file so that you can clearly understand
Output send below alert message
"The job "d.ksh" runing more then 10 time please check the process avoid hung issue"
"The job "a.ksh" runing more then 10 time please check the process avoid hung issue"
if we can addd job name with processid in the script that will be also fine
Basically the -o switch to ps allows you to select your own fields rather than use the defaults. This is particularly important in writing scripts that may be transferred to another platform, because the default selection of fields in ps -ef will be different if you move from Linux to Unix or MacOS X but ps -o will, with Yoda's caveats, most likely work. And if they don't, you will get an error rather than some odd misbehaviour that is hard to trace.
Multiple fields can be specified using a comma to separate each from the next. For instance, the default fields given by
ps
on my Ubuntu system are equivalent to
ps -opid,tty,time,comm
but if I wanted the parent-pid and effective user-id instead of the tty and the time I could type
ps -opid,ppid,euid,comm
And by changing the order of the field names you change their order in the output.
Appending the equals sign (=) to a field name suppresses its heading in the final output. Note, though, that you have to suppress the heading of every field, for example:
ps -opid=,ppid=,args= # right
ps -opid,ppid,args= # wrong, will only suppress the COMMAND heading
I hope that makes sense.
Getting the PIDs of the processes in the alert could be more tricky. If you use my original suggestion and have pgrep on your system you could use pgrep within the loop to inject the PIDs into your message.
for below script below script matching my requirement.
doubt- is it possible to print job with process ID if not please ignore
jobs=$(ps -u abcd -o comm= | awk '($1=="a.ksh" || $1=="d.ksh") && ++s[$1]==10')
if [[ -n "$jobs" ]]
then
printf "jobs runing longtime:\n%s\n" "$jobs"
exit 1
fi
---------- Post updated at 11:41 PM ---------- Previous update was at 07:42 PM ----------
HI I have almost near to my requirement
getting small issue need some correction while runing below script not fetching current runing full jobs name more then 10times
ps -u abcd -o comm= | awk '++s[$1]==10'
for example: runing more then time 10 time 3 different paths
For my server runing more then 100 jobs on different location/path using AIX operating system
While runing its fetching only ksh ,perl.java,c,pli like that not fetching full name of the jobs
Sure, you can add another -o pid= column, and you can change -o comm= to -o args=
Rule: put the predictable columns first, and have the args last!
ps -u abcd -o pid= -o args=
The trailing = means "don't print a header for this column", and all columns = means "don't print a header line at all".
apmcd47 mentioned a shorter notation but I found it does not work everywhere.
Does it look more promising now?
Postprocessing of args is problematic because it contains spaces. In awk you cannot simply refer to column $2 because your process name might be in $3 ...
lists the 10th occurrence of column#2, and if there are more than 10 it will not wipe a previously printed one
You can search for certain strings through the whole line like this