Question : 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

Answer : Help writing a ksh script on AIX box.

1) Is this actually a hanging session? I don't assume so, because there is a ttsession present, which will keep the script from doing anything.  Furthermore, the basic xterm is not a child of init but of gsl_09.07.007 which seems to be the "normal" situation.

Could it be that the problem arises the very moment this obscure gsl_09.07.007 vanishes and leaves xterm orphaned?

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

#!/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

You can't split lines in a shell script wherever you like. There are some syntax rules to be observed!

wmp

Random Solutions  
 
programming4us programming4us