Link to home
Start Free TrialLog in
Avatar of AIX25
AIX25Flag for United States of America

asked on

Help writing a ksh script on AIX box.

I need help to write a ksh script.

Users log on to a pc and open up a Reflection X sessions that talks to the AIX box and opens up a process for every user that runs this. Reflection X is a x-windows session.

Sample output:

rs3147:/> ps -ef |grep CATSTAR2
  c36787 368886 110636   0 14:07:24  pts/5  0:00 /usr/catia425/v425/code/steplib/CATSTAR2 CATIA 64 0 0 0
  c52077 421934 520350   0 14:02:35  pts/4  0:13 /usr/catia425/v425/code/steplib/CATSTAR2 CATIA 64 0 0 0
  c52193 434176  69862   0 08:11:10  pts/0  0:01 /usr/catia425/v425/code/steplib/CATSTAR2 CATIA 64 0 0 0

The problem is that when users logs off, it sometimes leaves those sessions running, and it inherits Parent ID of "0". I need help to create scripts that will go out and check to see if there is any processes running similar to the ones in the sample output above. But, I only want the script to kill the processes with a Parent ID of "0". I do not want to kill active processes.

Please help and reply back with any questions or more information needed.

Thank you
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

Hi,

you're a bit mistaken here. The "0" in the "C" (4th) column means "CPU utilization" and not the parent.
This field is under AIX only meaningful in a Workload Manager environment, else it's always zero.
The only process with a parent "0" is the "init" process., with a PID of 1, by the way.

So by which criterion should we select the processes to be killed?

Once you found such a criterion (I'll call it "search" below), you can do

kill $(ps -ef | grep "search" | grep -v grep | awk '{print $2}')

Maybe a possible selection criterion could be the missing TTY (the 6th column). Please check!

wmp





Avatar of AIX25

ASKER

Sorry for the mistake, let me explain.

The sample output I provided, does not have the output of what I'm looking for exactly. It was just a snapshot of active Reflection X processes.

I'm trying to create the hanging process, but have not managed yet. I should be able to get more on this tomorrow.

However, that the parent id will be "0" because that point the user cannot kill it, and root I believe owns the process. When that reflection x processes hangs, it causes them problems to use the x-session, and they have to create a ticket for a root user to go in and kill the hanging process. We are just trying to automate the process.

Also, in the 6th column, it will be a "-" for when the process is hung.

Are you familiar with Reflection X or this issue that is occurring with me? I hope I provided good information for you, please ask any other questions if you need more.

 

I'm not familiar with Reflection X but with other X servers for Windows. There should be no big difference.

Believe me, the parent id will never be "0", rather it will be "1" in case of an orphaned child adopted by "init", and the process is always owned by the user who started it, from all my experience with AIX.
(OK, there is some possibility for manipulation, but the user can't become "root")

But who knows, we're all still learning. I'm just too curious to see your sample output!

wmp


Avatar of ddup
ddup

kill $(ps -ef |awk '($3=0) && ($6="-") {print $2}')

Test with echo instead of kill first, make sure there is no other condition and you're not killing something useful

Avatar of AIX25

ASKER

Woolmilkporc,

I was mixed up...you are correct:"the parent id will never be "0", rather it will be "1" in case of an orphaned child adopted by "init"."

Then why is the user having trouble killing the process? Any ideas?

I will hopefully try to get you the sample output tomorrow.
Avatar of AIX25

ASKER

Forget that question, I know why...sorry.
Hey, ddup, great!

Finally we found a way to kill "init"

In a way it's sad that when init is older than 24 hours the "-" will move to $7, so we will not succeed in killing the beast...

wmp
AIX25: >> I know why <<

Why?
Avatar of AIX25

ASKER

Woolmilkporc, please break down your command and explain what it does. I'm not really

kill $(ps -ef | grep "search" | grep -v grep | awk '{print $2}')

ddup, please break down your command and explain it.

kill $(ps -ef |awk '($3=0) && ($6="-") {print $2}')

You guys are just beyond my understanding...compliment to both of you :)

Finally, which command will be using? Or which one is better for my situation?

Thanks

Avatar of AIX25

ASKER

AIX25: >> I know why <<

Why?

I'm guessing...the user's process that is hung, is not the same user logged in at that time and does not own, so would not be able to kill.

Correct?
ps -ef writes out the extended full process list
grep "search" searches this list for some keyword which I'm still ignoring.
grep -v grep takes care that grep will not find itself in the list
awk '{print $2}' prints out the second field of lines matching the above criteria ("search" contained but not "grep"). This field is the process id.
| (the pipe) takes the output of the preceeding cpmmand and feeds it to the following one.
$(  ...  ) gets replaced by the output of "..." (the above commands), e.g. "368886 421934 434176" (see your Q). This is basically the same as those old-school backticks ( ` ... ` )
kill is used to kill processes.

So my construct would finally expand to e.g.

kill 368886 421934 434176

That's all.

wmp





>> Correct? >>

Why should those users be different?

Do your users open a normal shell to then enter a command (" ... CATSTAR2 ...)?

In this case the owner of the "CATSTAR2" process should be the same as the one who opened the shell.

Or how does it work?

As for the question >> which command will be using? <<

ddup's suggested command will try to kill processes with parent 0, and the only such process is "init", the father of (nearly) all others. Doesn't make sense, IMO.
Beyond that, ddup's awk syntax is not quite correct ("=" instead of "==")

As you might have noticed, the command I suggested is not complete (we need the content of "search" and at least one more criterion to judge whether the process is orphaned.

Maybe this (following the approach in your question)

kill $(ps -ef -o pid,ppid,tty,args | grep CATSTAR2 | grep -v grep | awk '($2==1) && ($3=="-") {print $1}')

I modified the "ps" command to just print the four relevant fields, search for "CATSTAR" and modified the "awk" command to search for ppid "1" and tty "-"


... maybe you should actually first check which processes the command will capture -

ps -fp instead of kill, and the command between quotes - like this:

ps -fp "$(ps -ef -o pid,ppid,tty,args | grep CATSTAR2  | grep -v grep | awk '($2==1) && ($3=="-") {print $1}')"

wmp


And since you asked for a script - here is one, all in a line, and a bit "tuned":

ps -fp "$(ps -ef -o pid,ppid,tty,args | awk '($4~"CATSTAR2") && ($2==1) && ($3=="-") {print $1}')"  2>/dev/null ; [ $? -eq 1 ] && echo "No such process"

Use "kill" instead of "ps -fp" when you're satisfied with the result, but remove the quotes around $( ... ) beforehand:

kill $(ps -ef -o pid,ppid,tty,args | awk '($4~"CATSTAR2") &&  ($2==1) && ($3=="-") {print $1}') 2>/dev/null ; [ $? -eq 1 ] && echo "No such process"

Now my day is over.

Good night!

wmp
Avatar of AIX25

ASKER

Ok I have an update.

The user has closed the X-session and logged out of the system.

Then I run,

rs3147:/> ps -ef | grep CATSTAR
    root 438448 467144   0 11:50:25  pts/3  0:00 grep CATSTAR
  c36787 454872 385248   0 10:13:55  pts/1  0:04 /usr/catia425/v425/code/steplib/CATSTAR2 CATIA 64 0 0 0
rs3147:/>

Now, the user is no longer logged in, but his process is still running, so when he goes back to sign in, it will not let him open up a Reflection X session.

I need this script to no be user related.

What is the pts/1 for? I believe we can use that? Please let me know if you have any ideas, and if you can help me put in a script format?

Thank you
HI,

pts/1 is the pseudo terminal connected to the process. It is unique per (parent-) process and it is ever changing, so it will be useless as a selection criterion.

You write that the user had an X session. Now CATIA itself is not X, so I assume that the X session must be the parent of the process you posted.

Please issue

/usr/bin/proctree 454872

(if the process still exists, else choose another CATSTAR process id) and post the result.

We can then examine the process hierarchy to see what it's all about.

wmp


Avatar of AIX25

ASKER

rs3147:/> ps -ef |grep CATSTAR
    root 336022  77922   0 08:54:31  pts/2  0:00 grep CATSTAR
  c48276 401648 475346   0 07:31:07  pts/0  0:04 /usr/catia425/v425/code/steplib/CATSTAR2 CATIA 64 0 0 0
rs3147:/>

rs3147:/> /usr/bin/proctree 401648
57480    /usr/dt/bin/dtlogin -daemon
   340180    /usr/dt/bin/dtlogin -daemon
      467150    /usr/dt/bin/dtsession
         381082    xterm -e /catia/v425sp8/sbin/start_ds PROD catia >/dev/null 2>&1 A >/dev/null
            368810    /bin/ksh /catia/v425sp8/sbin/start_ds PROD catia >/dev/null 2>&1
               409720    /apps/csna/bin/call /catia/v425sp8/xosbin/start_ds PROD catia
                  90178    /bin/ksh /catia/v425sp8/xosbin/start_ds PROD catia
                     475346    /bin/sh /usr/catia425/v425/code/bin/catini -XM
                        401648    /usr/catia425/v425/code/steplib/CATSTAR2 CATIA 64 0 0 0
                           405616    catintr 0 11
Avatar of AIX25

ASKER

What is the best way to go about this for the script? Main problem is, when user exits out of the X-session and the X-session hangs, he can't reopen a new X-session the next day. Thats why I need this script to go out every night and kill these session. But, its not user dependent. I need it to go out and kill any hanging process and to NOT kill active X-sessions. How would we know or what indicates a hanging process to an active process?
Yes, AIX25,

I know what your problem is. No need to repeat it all the time  :-)

We'll have to analyze the process hierarchy a bit more.

Do I understand you right that it's the X terminal system which doesn't allow for a new session, and not CATIA?

Am I further right when assuming that it's not a hanging session whose proctree you posted?
Let's hope so, because if it was a hanging session we can clearly see that the hierarchy is complete nevertheless (no orphaned process with parent "init" somewhere inbetween), and so we will most probably not find a valid "killing" criterion.

Anyway, if it was not a hanging session, please wait for the next hanging process and post the output of

ps -fp "pid1 pid2"

for pid1 of the "xterm" process and  pid2 of the process one above it (the dtsession thing).

Let's see!

wmp
Avatar of AIX25

ASKER

User is still on vacation. Please await for outputs. Thank you.
Avatar of AIX25

ASKER

Please read the doc attached.
Doc1.doc
Avatar of AIX25

ASKER

Also, when I execute proctree "pid" on the CATIA process, nothing comes back when there is an abandoned session.

rs3147:/> proctree 98464
rs3147:/>


Avatar of AIX25

ASKER

Follow up:
For each result from the ps/grep commands
{
  Make sure that “CATSTAR” is the process & doesn’t just appear as parameter.
  If dtsession or ttsession exist for the UID – do nothing
  For each process returned by proctree for the PID
  {
    If the process belongs to the UID kill it
  }
}
I don't write scripts well....
I'll check what can be done using your info. Maybe I'll need some more outputs.
I'll be back ...
wmp
Hi,
following your directions I wrote this thingy -
#!/bin/ksh
ps -ef -o user,pid,comm | grep CATSTAR | while read line
  do
   set $line
    USER=$1
    PID=$2
    CMD=$3
     if [ $(ps -ef -o user,comm | grep $USER | grep -c dtsession) -ne 0 \
            -o $(ps -ef -o user,comm | grep $USER | grep -c ttsession) -ne 0 ]
      then :
       else
        for pid in $(proctree $PID 2>/dev/null | awk '{print $1}' | sort -nu)
          do
           if [ $(ps -f -o user= -p $pid 2>/dev/null) = $USER ]
             then
              ps -fp $pid
              echo kill $pid
           fi
          done
          echo "---"
     fi
  done
exit
Please note that the script as posted will display the affected processes and echo the appropriate kill statement - it will not do anything real.
Dry-run the script several times and check its outcome. Only if you're convinced that it will do the right thing remove echo and the line above it.
I could implement a parameter "REAL" (or the like) for this if you wish.
Be careful!
wmp

#!/bin/ksh
ps -ef -o user,pid,comm | grep CATSTAR | while read line
  do
   set $line
    USER=$1
    PID=$2
    CMD=$3
     if [ $(ps -ef -o user,comm | grep $USER | grep -c dtsession) -ne 0 \
            -o $(ps -ef -o user,comm | grep $USER | grep -c ttsession) -ne 0 ]
      then :
       else
        for pid in $(proctree $PID 2>/dev/null | awk '{print $1}' | sort -nu)
          do
           if [ $(ps -f -o user= -p $pid 2>/dev/null) = $USER ]
             then
              ps -fp $pid
              echo kill $pid
           fi
          done
          echo "---"
     fi
  done
exit

Open in new window

Avatar of AIX25

ASKER

Impressive!

I will test it Monday, when I get back to work. Thanks
Avatar of AIX25

ASKER

What does echo "---" mean...echo dashes? What is the dashes for? What will indicate that the script is successful?
OK,

I should have anticipated that my tiny dashes could irritate you.

We loop through a full process list searching for CATSTAR, and for every trove we start a whole bunch of
commands, which includes displaying in detail what we found.
The dashes are just meant to visibly separate the output related to each occurrence of CATSTAR in the process list,
nothing to worry about.

>> What will indicate that the script is successful <<

That's why I use

              ps -fp $pid              echo kill $pid

to display the selected processes and the associated kill commands.

It's your task to check whether we're going to slay the right victims.

Under normal circumstances (no abandoned session, i.e. no one  complaining of not being able to start a session) you should not see any output (except for the dashes, hehe!)

If you get some output however, ask the process owners whether they abandoned a session and/or whether they have problems starting a new one.

I fear you will have to exercise patience until there is actually such a complaint, to then immediately check what the script shows and whether killing the processes shown would help. It seems that you know which processes to kill in such a case ( >> they have to create a ticket for a root user to go in and kill the  hanging process <<).

If the script suggests killing the same processes as you would kill manually, remove the "echo" in front of "kill" to unleash the beast.

wmp







Avatar of AIX25

ASKER

Its amazing how you explain things, you make it very easy to understand scenarios!

"If the script suggests killing the same processes as you would kill manually, remove the "echo" in front of "kill" to unleash the beast."

I remove the echo in front of "kill $pid"

and...do I need to remove the line 16 in your script? Or removing the echo 17, will be enough the unleash the beast?


Glad I could put it across a bit.

Removing the echo in front of "kill $pid" is sufficient to arm the bomb.

Basically, once the script is tested and approved, lines 16 and 20 are nothing but decoration.
Throw them away if you don't want to leave any traces (we're killers, mind you!).

wmp

Avatar of AIX25

ASKER

woolmilkporc, please read the doc for update on my issue.

UpdateDoc.doc
Avatar of AIX25

ASKER

Also, I ran a proctree on the PID for catintr and it didn't return anything. So there was no ttsession or dtsession, which is good because that is the process we want to kill. Not really good with scripts...to know how to figure it out.
OK,

I think catintr is not displayed with "-o comm". Maybe we must use "-o args"

Please issue

ps -ef -o user,comm -p 483402
and
ps -ef -o user,args -p 483402
and
ps -ef  | grep c28872
and
proctree 483402

(if the process you mentioned in the doc is still "alive") and post what you get.

wmp
Our posts crossed ,as so often.

If proctree doesn't give any output, the process doesn't exist any more. That's all I can say.
Avatar of AIX25

ASKER

rs3147:/tmp> ps -ef |grep c28872
  c28872  69730 467156   0 13:30:37  pts/3  0:00 CATLICSL 2423
  c28872 303242      1   0   Jul 07      -  0:00 /apps/open/bin/ssh-agent
  c28872 352408      1   0 13:30:17      -  0:00 /apps/open/bin/ssh-agent
  c28872 368824      1   0 10:34:39      -  0:00 /apps/open/bin/ssh-agent
  c28872 380958 438386   0                  0:00 <defunct>
  c28872 393282 499784   0 13:30:36  pts/3  0:00 /bin/sh /usr/catia425/v425/code                                                                             /bin/catini -XM
  c28872 397396 516246   0 13:30:30  pts/3  0:00 /apps/csna/bin/call /catia/v425                                                                             sp8/xosbin/start_ds PROD catia
  c28872 409714 438386   0 13:30:36  pts/3  0:00 catintr 0 8
  c28872 438386 393282   0 13:30:36  pts/3  0:00 /usr/catia425/v425/code/steplib                                                                             /CATSTAR2 CATIA 64 0 0 0
    root 454786 421888   0 13:36:46  pts/1  0:00 grep c28872
  c28872 467156      1   0 13:30:36  pts/3  0:00 /bin/ksh /usr/catia425/v425/cod                                                                             e/bin/catlicsr 2423
  c28872 483438      1   0 13:30:30      -  0:00 xterm -e /catia/v425sp8/sbin/st                                                                             art_ds PROD catia >/dev/null 2>&1 &
  c28872 499784 397396   0 13:30:30  pts/3  0:00 /bin/ksh /catia/v425sp8/xosbin/                                                                             start_ds PROD catia
  c28872 516246 483438   0 13:30:30  pts/3  0:00 /bin/ksh /catia/v425sp8/sbin/st                                                                             art_ds PROD catia >/dev/null 2>&1 &
rs3147:/tmp>
Avatar of AIX25

ASKER

I'm not sure if I mentioned this or if I was clear, and of course all previous conversations with CATSTAR, will be replaced with catintr.

The dtsession and ttsession were never part of the proctree of catintr. The dtsession and ttsession were processes for the user. So, if catintr process is found for any user, and there is no dtsession or ttsession processes running for that user, then we kill catintr.
Avatar of AIX25

ASKER

catintr is abandoned session, so I believe there should not be anything under the proctree.

Thanks
1) Where is the output I requested?

2) >> if catintr process is found for any user, and there is no dtsession or  ttsession processes running for that user, then we kill catintr <<

I was told to do

... if (catintr) process is found for any user, and there is no  dtsession or  ttsession processes running for that user, then we kill all processes for that user.

What now?

3) >> catintr is abandoned session, so I believe there should not be anything  under the proctree <<
How should the OS know about abandoned sessions, and even if it knew, why shouldn't it show that process in proctree? After all it's a process, and I never heard about AIX manipulating the output of its commands like that.

If you insist in (3) being the case nevertheless, we can make it easy: Search for catintr processes, and if such a process doesn't show up in proctree, kill it. Is this what the script is supposed to do? No problem!
Avatar of AIX25

ASKER

Sorry, I forgot to post the outputs you requested. I have attached a doc for the outputs.

command-outputs.doc
Avatar of AIX25

ASKER

I'm sorry for the mix too! The analyst gives me one thing, then changes on me.

Final product needed is here:
Any user that has catintr process, with no dtsession and ttsession. Kill catintr and all of its parent pid's pertaining to that user. catintr will not have any children pid's.

Please ask more questions, if I was not clear. Thank you and sorry for causing a confusion.
OK,

first thing I saw is that we actually don't catch catintr with "-o comm". We need "-o args". But that's no problem.

A very, very strange thing is that "proctree" phenomenon.

As you can see in your output

409174 (catintr) is a child of 438386 (CATSTAR2) is a child of 393282 (catini) is a child of 499784 ( ksh xosbin/start_ds) is a child of 397396 (xosbin/start_ds) is a child of 516246 (ksh sbin/start_ds) is a child of 483438 (xterm sbin/start_ds) is a child of 1 (init).

If this ain't a process tree what else should be one?

Please change line 2 to

ps -ef -o user,pid,args | grep catintr | while read line

let it "dry run" and see (post) what you get.

If this proctree mischief persists I will try to climb up the tree manually, but probably not before tomorrow.

wmp
A thing I didn't take seriously at first sight - the "xterm .../sbin/start_ds" is a son of init (1).
Maybe it could be enough to search for an adopted xterm to kill it and all its breed??

Please try

ps -ef | grep 483438
and if it's still there
proctree 483438

and

ps -ef | grep xterm

to see if there are more adopted xterms (this would be a show-stopper then)
Avatar of AIX25

ASKER

The abandoned process of catintr is gone, I will have the user try to create it tomorrow.

Also,

409174 (catintr) is a child of 438386 (CATSTAR2) is a child of 393282 (catini) is a child of 499784 ( ksh xosbin/start_ds) is a child of 397396 (xosbin/start_ds) is a child of 516246 (ksh sbin/start_ds) is a child of 483438 (xterm sbin/start_ds) is a child of 1 (init).

Would we be able to kill everything above catintr...to their parent id of 1? Because, if we can, that will work.

But,

I will get the user to create that abandoned catintr process, "dry run", and then post here.

Thanks
>> kill everything above catintr >>

Yes, that could be just easy if there were a proctree. But without it .. lots of grepping etc....

Let's see.
Avatar of AIX25

ASKER

I will get these outputs for you tomorrow.:

Please try

ps -ef | grep 483438
and if it's still there
proctree 483438

and

ps -ef | grep xterm
Please remember that the PID to grep for (the now-gone 483438 above) is the one of the adopted xterm at the top of the hierarchy (just below init) which ends in catintr.
Avatar of AIX25

ASKER

rs3147:/> ps -ef |grep catintr
  c28872 454860 319516   0 09:48:21  pts/2  0:00 catintr 0 8
    root 458772 381096   0 09:51:37  pts/1  0:00 grep catintr
rs3147:/>

rs3147:/> ps -ef  | grep c28872
  c28872  90322 397320   0 09:48:15      -  0:00 xterm -e /catia/v425sp8/sbin/st                                                                             art_ds PROD catia >/dev/null 2>&1 &
  c28872 106618 385160   0 09:48:21  pts/2  0:00 /bin/sh /usr/catia425/v425/code                                                                             /bin/catini -XM
  c28872 110830      1   0 09:47:46      -  0:00 /apps/open/bin/ssh-agent
  c28872 303242      1   0   Jul 07      -  0:00 /apps/open/bin/ssh-agent
  c28872 319516 106618   0 09:48:21  pts/2  0:00 /usr/catia425/v425/code/steplib                                                                             /CATSTAR2 CATIA 64 0 0 0
  c28872 336044 376996   0 09:49:37  pts/3  0:00 -ksh
  c28872 340222      1   0 09:48:21  pts/2  0:00 /bin/ksh /usr/catia425/v425/cod                                                                             e/bin/catlicsr 2423
  c28872 352408      1   0 13:30:17      -  0:00 /apps/open/bin/ssh-agent
  c28872 364616 340222   0 09:48:21  pts/2  0:00 CATLICSL 2423
  c28872 368824      1   0 10:34:39      -  0:00 /apps/open/bin/ssh-agent
  c28872 385160 450736   0 09:48:15  pts/2  0:00 /bin/ksh /catia/v425sp8/xosbin/                                                                             start_ds PROD catia
  c28872 393440  90322   0 09:48:15  pts/2  0:00 /bin/ksh /catia/v425sp8/sbin/st                                                                             art_ds PROD catia >/dev/null 2>&1 &
  c28872 397320 516330   0 09:48:04      -  0:00 /apps/csna/rsbin/gsl_09.07.007                                                                              /apps/csna/datalib/gsl_aix.v5r18prod.properties &
    root 421920 381096   0 09:52:21  pts/1  0:00 grep c28872
  c28872 450736 393440   0 09:48:15  pts/2  0:00 /apps/csna/bin/call /catia/v425                                                                             sp8/xosbin/start_ds PROD catia
  c28872 454860 319516   0 09:48:21  pts/2  0:00 catintr 0 8
  c28872 483484  69664   0 09:47:45      -  0:00 /usr/dt/bin/dtsession
  c28872 487644 319516   0                  0:00 <defunct>
  c28872 512060      1   0 09:47:48      -  0:00 /usr/dt/bin/ttsession -s
  c28872 516330      1   0 09:48:04      -  0:00 /usr/dt/bin/dtexec -open 0 -ttp                                                                             rocid 2.1CG74K 01 512060 1342177314 1 1 9473 167.186.190.105 4_101_1 /apps/csna/                                                                             rsbin/gsl_09.07.007 /apps/csna/datalib/gsl_aix.v5r18prod.properties &
rs3147:/>

rs3147:/> ps -ef |grep xterm
  c28872  90322 397320   0 09:48:15      -  0:00 xterm -e /catia/v425sp8/sbin/start_ds PROD catia >/dev/null 2>&1 &
rs3147:/>

rs3147:/> ps -ef |grep 90322
    root  77932 381096   0 09:55:31  pts/1  0:00 grep 90322
  c28872  90322 397320   0 09:48:15      -  0:00 xterm -e /catia/v425sp8/sbin/start_ds PROD catia >/dev/null 2>&1 &
  c28872 393440  90322   0 09:48:15  pts/2  0:00 /bin/ksh /catia/v425sp8/sbin/start_ds PROD catia >/dev/null 2>&1 &
rs3147:/>

rs3147:/> proctree 90322
rs3147:/> Nothing came back

Avatar of AIX25

ASKER

I ran the scrip and here is the output:

rs3147:/tmp> ./test*
---
rs3147:/tmp>
Avatar of AIX25

ASKER

I ran it again, this is what I got:

rs3147:/tmp> ./test_script
./test_script[8]: test: 0403-021 A ] character is missing.
Usage: grep [-r] [-R] [-H] [-L] [-E|-F] [-c|-l|-q] [-insvxbhwy] [-p[parasep]] -e pattern_list...
        [-f pattern_file...] [file...]
Usage: grep [-r] [-R] [-H] [-L]  [-E|-F] [-c|-l|-q] [-insvxbhwy] [-p[parasep]] [-e pattern_list...]
        -f pattern_file... [file...]
Usage: grep [-r] [-R] [-H] [-L] [-E|-F] [-c|-l|-q] [-insvxbhwy] [-p[parasep]] pattern_list [file...]
./test_script[10]: ttsession:  not found.
./test_script[10]: -ne:  not found.
---
./test_script[8]: test: 0403-021 A ] character is missing.
Usage: grep [-r] [-R] [-H] [-L] [-E|-F] [-c|-l|-q] [-insvxbhwy] [-p[parasep]] -e pattern_list...
        [-f pattern_file...] [file...]
Usage: grep [-r] [-R] [-H] [-L]  [-E|-F] [-c|-l|-q] [-insvxbhwy] [-p[parasep]] [-e pattern_list...]
        -f pattern_file... [file...]
Usage: grep [-r] [-R] [-H] [-L] [-E|-F] [-c|-l|-q] [-insvxbhwy] [-p[parasep]] pattern_list [file...]
./test_script[10]: ttsession:  not found.
./test_script[10]: -ne:  not found.
---
rs3147:/tmp>
Avatar of AIX25

ASKER

Here is the script I ran:

#!/bin/ksh
ps -ef -o user,pid,args | grep catintr | while read line
  do
   set $line
    USER=$1
    PID=$2
    CMD=$3
     if [ $(ps -ef -o user,comm | grep $USER | grep -c dtsession)

-ne 0 \
            -o $(ps -ef -o user,comm | grep $USER | grep -c

ttsession) -ne 0 ]
      then :
       else
        for pid in $(proctree $PID 2>/dev/null | awk '{print $1}' |

sort -nu)
          do
           if [ $(ps -f -o user= -p $pid 2>/dev/null) = $USER ]
             then
              ps -fp $pid
              echo kill $pid
           fi
          done
          echo "---"
     fi
  done
exit
ASKER CERTIFIED SOLUTION
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of AIX25

ASKER

I am lost... "2) No wonder that the script fails, with all those extra linefeeds! Where do they come from?"

So, will we not be able to get this script working?
Compare your script and the one in my last post.
I removed the line splits (wherever they came from), so it will work again.
Avatar of AIX25

ASKER

Ok, so this is the final product that will work for a user's reflection-x session is abandoned? Please let me know. Also, does this site pay you? Is there way I can send over a tip or something? You have stuck till the end with me and appreciate your expertise and efforts.
Er,

"No" to all your questions!

No, I just don't know whether this script will actually help you. I followed word-by-word your instructions (the ones coming from your analyst, as you wrote).  You will have to test, test, test and see what comes out.

No one of us experts gets paid here. (OK, we get an EE shirt from time to time when reaching a new rank).

No, we do not want to get paid (at least I don't). I'm glad to help, that's all. Besides that I'm rather sure that asking for or accepting a fee is against EE's rules.

Don't worry, I will assist you in the future as I did in the past, without a fee but to my best knowledge and belief nonetheless.

Cheers

wmp


Avatar of AIX25

ASKER

Ok, I will test this script when this issue occurs. I might open a future question related to this one...thanks for all your help!
Avatar of AIX25

ASKER

woolmilkporc,

I needed to clarify one more thing. Would the script be more successful or sure to work...If we were to keep the same concept of grep  catinr and look for dtsession ttsession. But, instead of killing the process tree pertaining to catintr, to just kill everything for the user. What I basically mean, if we grep catintr for any user, and find no dtsession or ttsession, kill every process for that user. Will that work better? Let me know, if  should open a new question for this...thanks!
Killing the process tree for catintr makes more sense, of course.

But for some very, very strange reason we don't get a process tree with 'proctree'.

Maybe 'proctree -ap $PID' could work better, but I can't tell you for sure, because just a simple 'proctree $PID' works for me in all cases. OK, I don't have 'catintr' on my system, that's true.

Try the script "as is" when you have the next true hanging process, and see if it prints anything at all (except for those famous dashes ---).

wmp