LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How to tell where the execution is going on right now? (https://www.linuxquestions.org/questions/programming-9/how-to-tell-where-the-execution-is-going-on-right-now-308883/)

bahadur 04-02-2005 04:37 AM

How to tell where the execution is going on right now?
 
i have a very unique problem.

now i have a big shell script and within that shell script i hop from one place to another.

now we have commands like

pwd

which tell u in which directory u are at a particular moment.

similarly i wan to know of a command which call tell me that where my script is at a particular moment.

e.g.

Code:

              cd directory1
              echo " the program is now in the directory `the_wanted_command`"
              cd directory2
              echo " the program is now in the directory `the_wanted_command`"

where `the_wanted_command` is the command i am looking for.

so every time i change the directory within the code i want to list the complete path where i am.

just like pwd directory gives me the path of where i am in the file system i want a command which can do exactly the same for the process being executed.

Mara 04-02-2005 08:22 AM

Hmmm...
Code:

#!/bin/bash
echo `pwd`
cd /
echo `pwd`
cd /etc
echo `pwd`

and the result is
Code:

/tmp
/
/etc


bahadur 04-02-2005 08:32 AM

some how in my case it gives me the present working directory of where i am logged in at the time of the execution of the script and not the script itself.

jlliagre 04-02-2005 11:10 AM

Solaris has pwdx, under Linux, you can parse "ls -l /proc/$pid/pwd@" output.

bahadur 04-02-2005 10:57 PM

buddy can u please explain a little about ur code.?

specially what is PID and what is pwd@?

pcweirdo 04-02-2005 11:48 PM

PID: process ID. Every process (program) that starts has a unique id. To see them, type
$ ps aux
at the terminal. Note that you shouldn't type the $ sign.
In relation to jlliagre's post, /proc/self/cwd might work a bit easier.

bahadur, can you post the script you're working with, or at least some of it? That would make helping you a lot easier.

Thanks,
pcweirdo.

bahadur 04-03-2005 12:48 AM

here is the code

Code:

recursive()
          {
            local DIRNAME="$1"
            local DIRPERM="$2"
            local FILEPERM="$3"
            local SEARCHSTR="$4"
            echo "Processing the directory: $DIRNAME"
           
            cd "$DIRNAME"
           
            FILES=`ls -p |awk '! /\// {print}'`
            DIREC=`ls -F |awk '/\// {print}'|tr -d "/"`
                   
                for FIL in $FILES
                    do
                      if [ $# -eq 4 ];then echo $FIL |grep "$SEARCHSTR">/dev/null                   
                      if [ $? = 0 ];then echo " Matched File: $FIL";else echo;fi
                      else echo;fi                       
                      $actualpath"/"permissions.sh "$FIL" "$FILEPERM"
                    done
           
                for DIR in $DIREC
                    do
                      $actualpath"/"permissions.sh "$DIR" "$DIRPERM"
                      recursive "$DIR" "$DIRPERM" "$FILEPERM" "$SEARCHSTR"
                      cd ..
                    done               
            }
            actualpath=`dirname $0`
            recursive $1 $2 $3 $4 $actualpath


in all the places where i have used the variable $actualpath i would lilke to use the pwdx pid.

now can any one just tell me how can a shell script obtain its ownprocess ID?

jlliagre 04-03-2005 03:42 AM

Quote:

what is pwd@?
a pseudo file in the /proc file system, which is a symbolic link to the current working directory of the corresponding process.
Quote:

now can any one just tell me how can a shell script obtain its ownprocess ID?
Code:

myPid=$$


All times are GMT -5. The time now is 06:56 PM.