LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 04-02-2005, 04:37 AM   #1
bahadur
Member
 
Registered: Apr 2004
Distribution: Linux Red Hat
Posts: 141

Rep: Reputation: 15
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.
 
Old 04-02-2005, 08:22 AM   #2
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,536

Rep: Reputation: 148Reputation: 148
Hmmm...
Code:
#!/bin/bash
echo `pwd`
cd /
echo `pwd`
cd /etc
echo `pwd`
and the result is
Code:
/tmp
/
/etc
 
Old 04-02-2005, 08:32 AM   #3
bahadur
Member
 
Registered: Apr 2004
Distribution: Linux Red Hat
Posts: 141

Original Poster
Rep: Reputation: 15
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.
 
Old 04-02-2005, 11:10 AM   #4
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,499

Rep: Reputation: 355Reputation: 355Reputation: 355Reputation: 355
Solaris has pwdx, under Linux, you can parse "ls -l /proc/$pid/pwd@" output.
 
Old 04-02-2005, 10:57 PM   #5
bahadur
Member
 
Registered: Apr 2004
Distribution: Linux Red Hat
Posts: 141

Original Poster
Rep: Reputation: 15
buddy can u please explain a little about ur code.?

specially what is PID and what is pwd@?
 
Old 04-02-2005, 11:48 PM   #6
pcweirdo
Member
 
Registered: Oct 2004
Location: Melbourne-ish, Australia
Distribution: Gentoo, Windows XP Pro
Posts: 58

Rep: Reputation: 15
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.
 
Old 04-03-2005, 12:48 AM   #7
bahadur
Member
 
Registered: Apr 2004
Distribution: Linux Red Hat
Posts: 141

Original Poster
Rep: Reputation: 15
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?

Last edited by bahadur; 04-03-2005 at 12:49 AM.
 
Old 04-03-2005, 03:42 AM   #8
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,499

Rep: Reputation: 355Reputation: 355Reputation: 355Reputation: 355
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=$$
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pause Execution in VB ashirazi Programming 2 08-17-2005 06:17 PM
Remote Execution issinho Linux - Networking 5 07-08-2005 01:11 PM
loop execution suchi_s Programming 4 11-05-2004 08:06 AM
Java... execution ? gluon Programming 2 02-08-2002 01:13 PM
Timed Execution Undead Programming 5 09-13-2001 02:57 AM


All times are GMT -5. The time now is 09:23 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration