1

I have an AIX production server, there is a script A.sh running on it. i have no root access for this server. i want to find out argument passing value of this A.sh script. How can i get this value?

Is there any provision inside /proc/processID?

The following is not working. I tried by generating a script:

echo "Hello $1 $2 $3"

while [ 1 ]
do
   sleep 2
   echo $$
done

Then I run this script by

test.sh 1  2 3

Output:

$ cat /proc/3107/cmdline
-bash$

As per suggestion by @Cyrus suggestion I expect

1 2 3 

which are the arguments I passed in, but it is not working like that.

tripleee
  • 175,061
  • 34
  • 275
  • 318
user3559721
  • 134
  • 8

2 Answers2

2

you can try:

cat /proc/PROCESSID/cmdline
UtLox
  • 3,744
  • 2
  • 10
  • 13
  • 1
    I suggest to append `| tr '\0' ' '`. – Cyrus Sep 04 '19 at 05:18
  • To exactly get the parameters, exclude the calling program by appending `| cut -d ' ' -f 3-` from the `tr` piped output as told by @Cyrus. For e.g., `cat /proc/$(pgrep -f test.sh)/cmdline | tr '\0' ' ' | cut -d ' ' -f 3-` – sungtm Sep 04 '19 at 06:09
1

This should work:

cat /proc/3107/cmdline | tr '\0' ' ';

Alternatively you can use:

ps -ef | grep script.sh | grep -v grep

where script.sh is the name of your script which is running now.

Steps for verifying this:

  1. Create a script named script.sh and paste the below code in it:

    #!/bin/bash
    while :
    do
      echo "Press [CTRL+C] to stop.."
      sleep 1
    done
    
  2. Save the file (:wq! from vi editor ).

  3. Make it executable by

    chmod a+x script.sh
    
  4. Run the script by issuing command-line options like this:

    ./script.sh var1 val1 var2 val2 var2 val4
    
  5. Open another terminal (duplicate session) and issue:

    ps -ef | grep script.sh | grep -v grep 
    

You should be able to see something like this:

username 12227  2268  0 07:48 pts/98   00:00:00 /bin/bash ./script.sh var1 val1 var2 val2 var2 val4 var4
1218985
  • 7,531
  • 2
  • 25
  • 31
  • Oh ok, which means your process is not running. Do you see the exit status 1 after issuing the above command? (You can run echo $? to check the exit code). I have updated the steps for creating the script and testing it. You can follow that. – 1218985 Sep 04 '19 at 06:15
  • @ https://stackoverflow.com/users/1218985/sarath-kumar-sivan this is working in ubuntu but not know about AIX server. Is this solution is worked on AIX IBM ? – user3559721 Sep 04 '19 at 07:56