AIX

AIX

Connect with fellow AIX users and experts to gain knowledge, share insights, and solve problems.

 View Only
  • 1.  Scripting 101

    Posted Sun April 22, 2012 08:35 PM

    Originally posted by: SystemAdmin


    Hi there!

    I'm not that good at scripting, can somebody help me.

    I have a file(apps_pid.txt) that contains the following below, these are process listed and saved to a text file. I wan't to ps -ef grep those below to know what is using.

    #vi apps_pid.txt

    23422
    30023
    2343
    23421
    21232
    10023

    I want to know what is using on this PID.

    Thanks


  • 2.  Re: Scripting 101

    Posted Mon April 23, 2012 05:23 AM

    Originally posted by: wdephoff


    Hi,
    here a "quick and dirty" Kornshell-Script (running under Linux)

    I have a file (apps_pid.txt) with Process-IDs:

    
    3075 3175 2955
    


    The output for Process 3075 is:

    
    ps -ef |grep 3075 wolfgang  3075  3073  0 10:51 ?        00:00:00 /usr/sbin/mysqld --defaults-file=/home/wolfgang/.local/share/akonadi
    //mysql.conf --datadir=/home/wolfgang/.local/share/akonadi/db_data/ --socket=/home/wolfgang/.local/share/akonadi/socket-tsmsrv1/mysql.socket
    


    for Process 3175 (note the multiple lines with PPID):

    
    ps -ef |grep 3175 tsminst1  3175  3134  5 10:52 ?        00:00:54 db2sysc 0 root      3177  3175  0 10:52 ?        00:00:00 db2ckpwd 0 root      3180  3175  0 10:52 ?        00:00:00 db2ckpwd 0 root      3181  3175  0 10:52 ?        00:00:00 db2ckpwd 0 tsminst1  3188  3175  0 10:52 ?        00:00:01 db2vend (PD Vendor Process - 1)
    


    and for process 2955:

    
    ps -ef |grep 2955 root      2955     1  0 10:51 ?        00:00:00 /opt/tivoli/tsm/db2/bin/db2fmcd
    


    here my script (get_ps.ksh):

    
    #/usr/bin/ksh cat apps_pid.txt|
    
    while read line 
    
    do set $line pid=$1 ps -ef |grep -v grep|grep $pid|
    
    while read line1   # loop thru all line with the pid 
    
    do set $line1        # get user and process id as field 1 and 2 user=$1 xpid=$2 
    
    if [ 
    "$xpid" -eq 
    "$pid" ]  # filter the lines whith PID as field 2 then shift 7     # shift the hole line to the left, to get the Process-description proc=$* echo 
    "PID: $pid - User: $user" echo 
    "Proc: $proc" echo 
    "\n" 
    
    else 
    
    continue fi done done
    


    and the Output:
    
    ./get_ps.ksh PID: 3075 - User: wolfgang Proc: /usr/sbin/mysqld --defaults-file=/home/wolfgang/.local/share/akonadi
    //mysql.conf --datadir=/home/wolfgang/.local/share/akonadi/db_data/ --socket=/home/wolfgang/.local/share/akonadi/socket-tsmsrv1/mysql.socket     PID: 3175 - User: tsminst1 Proc: db2sysc 0     PID: 2955 - User: root Proc: /opt/tivoli/tsm/db2/bin/db2fmcd
    

    I hope this helps you.

    regards
    Wolfgang


  • 3.  Re: Scripting 101

    Posted Mon April 23, 2012 05:26 AM

    Originally posted by: SystemAdmin


    Thanks Wolfgang! will try this and give feedback the soonest...


  • 4.  Re: Scripting 101

    Posted Mon April 23, 2012 05:51 AM

    Originally posted by: SystemAdmin


    It works fine Wolfgang, thanks for the help!!!


  • 5.  Re: Scripting 101

    Posted Mon April 23, 2012 08:04 PM

    Originally posted by: SystemAdmin


    Hi Wolfgang,

    Have encounter a new prob on my script, this is a new one, as i intend to automate those manual commands. This is to identify ports which uses on the AIX box.

    Here, i do netstat -Aan directed to a file, output something like this

    
    Active Internet connections (including servers) PCB/ADDR         Proto Recv-Q Send-Q  Local Address      Foreign Address    (state) f1000e00003eb3b0 tcp        0      0  *.*                   *.*                   CLOSED f1000e0000a6d3b0 tcp4       0      0  *.*                   *.*                   CLOSED f1000e000189b3b0 tcp4       0      0  *.22                  *.*                   LISTEN f1000e0001cc13b0 tcp4       0      0  *.111                 *.*                   LISTEN f1000e00001683b0 tcp        0      0  *.427                 *.*                   LISTEN f1000e0001f7cbb0 tcp4       0      0  133.100.206.16.22     10.0.5.212.58302      ESTABLISHED f1000e00002d63b0 tcp4       0     52  133.100.206.16.22     10.0.5.212.58315      ESTABLISHED f1000e0001f12bb0 tcp        0      0  *.6988                *.*                   LISTEN f1000e0001cc73b0 tcp4       0      0  *.32769               *.*                   LISTEN
    


    then, trimmed down and write to a file socket.txt these lines.

    
    f1000e00003eb3b0 f1000e0000a6d3b0 f1000e000189b3b0 f1000e0001cc13b0 f1000e00001683b0 f1000e0001f7cbb0 f1000e00002d63b0 f1000e0001f12bb0 f1000e0001cc73b0
    


    I want to know which is using the port using the command rmsock f1000e00003eb3b0 tcpcb.

    
    # rmsock f1000e00003eb3b0 tcpcb The socket 0xf1000e00003eb008 is being held by proccess 6094988 (rmcd). # ps -ef|grep 6094988 root  6094988  2556010   0   Dec 07      -  5:07 /usr/sbin/rsct/bin/rmcd -a IBM.LPCommands -r
    


    Having a problem how can i use the tcpcb in the script.

    Regards


  • 6.  Re: Scripting 101

    Posted Sun April 29, 2012 08:20 PM

    Originally posted by: SystemAdmin


    Found solution to my query, this thread can already tar as answered! many Thanks