[Solved] how Execute a Perl Script from any location on the machine


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [Solved] how Execute a Perl Script from any location on the machine
# 1  
Old 08-19-2010
Error [Solved] how Execute a Perl Script from any location on the machine

hi guys,


i have a query, i wrote a perl script that will collect cpu statistics

Code:
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

Code:
$/home/ravi/perl
cpu.pl


i tried this by adding the following line to my file

Code:
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
# 2  
Old 08-19-2010
Include current directory "." in PATH variable.
Code:
export PATH=.:$PATH

Or put cpu.pl in /arbitrary/directory, and
Code:
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.
# 3  
Old 08-19-2010
no its not working....same issue....


i forgot to mention one more thing my source file is at location

Code:
$/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
# 4  
Old 08-19-2010
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:
Code:
. /home/ravi/.bashrc
or
source /home/ravi/.bashrc

# 5  
Old 08-19-2010
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"
# 6  
Old 08-19-2010
Use your favorite editor and open /home/ravi/.bashrc
At the end of that file, you add this line:
Code:
export PATH=/home/ravi/perl:$PATH

Save and exit.
And execute:
Code:
source /home/ravi/.bashrc

And run:
Code:
cpu.pl

# 7  
Old 08-19-2010
i am getting this error

-ksh: .[1]: bind: not found [No such file or directory]
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

PERL: In a perl-scripttTrying to execute another perl-script that SETS SOME VARIABLES !

I have reviewed many examples on-line about running another process (either PERL or shell command or a program), but do not find any usefull for my needs way. (Reviewed and not useful the system(), 'back ticks', exec() and open()) I would like to run another PERL-script from first one, not... (1 Reply)
Discussion started by: alex_5161
1 Replies

2. Shell Programming and Scripting

Execute shell script on remote machine

I want to execute a shell script(set of commands) on remote machine and that script takes input from text file(local machine). Please refer below: ssh user@hostname 'bash -s'< ./test.sh file.txt But i got the error file.txt doesn't exist. Can anyone help me on this. Content of test.sh: ... (2 Replies)
Discussion started by: manishtri88
2 Replies

3. UNIX for Dummies Questions & Answers

Execute shell script in remote machine

Hi All, We have 2 servers A and B. B is having a sctipt called b.sh in path /home/dev/scripts. Now my requirement is i want to execute b.sh from server A. Kindly help me. (3 Replies)
Discussion started by: Girish19
3 Replies

4. IP Networking

Execute script located on a remote machine

So, is there way of automating this ? My ultimate goal is to run some cmd script in windows and it should connect to a remote unix host and run a script x.sh located on the remote unix host. I was wanting to achieve this by using WinSCP and Putty only. If possible let me know how and if not... (25 Replies)
Discussion started by: mohtashims
25 Replies

5. Red Hat

Sudo to execute script without passwd[solved]

Hi Hope someone can sched some light i'm trying to execute a script via sudo but i don't want to be prompted for a password when i run the script using sudo my sudo entry does work in that the script gets executed but i'm having to give a password, my current entry is given below user1 ... (0 Replies)
Discussion started by: duckeggs01
0 Replies

6. Shell Programming and Scripting

execute script from any location.

Hello, Can someone tell me the method to execute the script from any location on linux server whereas It resides on a particular location e.g.: Suppose script resides at this location /efare1/dist/src monitor.sh But I want If user know the name of the script he should not remember... (2 Replies)
Discussion started by: anuragpgtgerman
2 Replies

7. Shell Programming and Scripting

How to execute the same script on another machine

Recently, I need to generate a lot of files from a few master files. In fact, if I relogin to the server machine, my operating would be much faster. My question is this: Can I write a script in which the current path can be automatically saved and relogin to the server to execute my command in the... (0 Replies)
Discussion started by: jiao
0 Replies

8. Shell Programming and Scripting

To execute the same script in another machine

We have a few machines which share the same directory. How can I execute the same script under that directory in different machine while I am using mine? (1 Reply)
Discussion started by: jiao
1 Replies

9. Shell Programming and Scripting

How to execute a script hosted on a machine from a different machine

Hi everyone I intend to trigger a script from one machine say mc1 that actually excutes on different machine say mc2 and redirect the logs to that machine mc2. I tried to use nohup <nfs location of machine >/script.sh > <nfs location of machine >/script.log 2>&1 & nfs location of... (2 Replies)
Discussion started by: harneetmakol
2 Replies

10. Shell Programming and Scripting

how to execute a script on remote machine

hi unix guru's i am new to unix shell programming. i found a trouble in executing a script(bali.ksh) which is available on serverA with username xyza, this script contains sqlplus command to retrive the data from the database available on other serverC. Now i need to run the above script... (4 Replies)
Discussion started by: balireddy_77
4 Replies
Login or Register to Ask a Question