hi guys,
i have a query, i wrote a perl script that will collect cpu statistics
Scripts/myScripts/
cpu.pl
i want to make this file so that i can run it from any location on any drive,
without giving the path explicitly.
like
$/home/ravi/perl
cpu.pl
i tried this by adding the following line to my file
system("cd /Scripts/myScripts") or die "Can't change the directory";
but its not working....
can someone help me with this issue.....
thanks and regards
Include current directory "." in PATH variable.
export PATH=.:$PATH
Or put cpu.pl in /arbitrary/directory, and
export PATH=/arbitrary/directory:$PATH
---------- Post updated at 08:44 AM ---------- Previous update was at 08:27 AM ----------
You may be considering adopt the first suggestion, but you need to read this post before you take action.
no its not working....same issue....
i forgot to mention one more thing my source file is at location
$/home/ravi/perl
im supposed to execute at location
$/home/ravi/Scripts/myScripts
so everytime when i want to execute i have to go "$/home/ravi/Scripts/myScripts" and execute
so i want to make it so that i need not go to "$/home/ravi/Scripts/myScripts" location everytime to execute.
from any directory i want to execute it as just cpu.pl
SORRY FOR MENTIONING THESE DETAILS
Sorry, I forgot to mention that you need to source the file in which you export the PATH variable.
Let's say you export your PATH variable in "/home/ravi/.bashrc", you need to do this after that:
. /home/ravi/.bashrc
or
source /home/ravi/.bashrc
sorry,
i din understand....
can u elaborate on this....
location of my code is "$/home/ravi/perl"
and everytime i need to execute at "$/home/ravi/Scripts/myScripts"
and my file is "cpu.ksh"
Use your favorite editor and open /home/ravi/.bashrc
At the end of that file, you add this line:
export PATH=/home/ravi/perl:$PATH
Save and exit.
And execute:
source /home/ravi/.bashrc
And run:
cpu.pl
i am getting this error
-ksh: .[1]: bind: not found [No such file or directory]
In Korn Shell you may need to use .(dot) to source files. I am using Bash Shell, am not sure.
Try this:
. /home/ravi/.bashrc
yeah it worked.....u have given for bash shell.....i did the same to .kshrc file and it worked.....thank you soo much it was very useful....