flamey Posted November 26, 2006 Posted November 26, 2006 i've wrote a Perl script to execute as a cron job. the script suppose to write some data to a text file in the same folder the script is in. i hard coded the path to the script's folder (/home/myaccount/public_html/cgi-bin/myscript/logfile.txt) and it works fine, but if i just use logfile.txt, this file is saved in (/home/myaccount/logfile.txt). the $ENV{} stuff doesn't work, i guess it just runs as if executed from command prompt. how can i find a path the script is located in/executing from, so i don't have to modify my script when i need to move it? thanks in advance! Quote
TCH-Andy Posted November 26, 2006 Posted November 26, 2006 Hi Flamey, I don't think you can in perl, I think you need to tell it the directory you want it writing to. Quote
TCH-Andy Posted November 26, 2006 Posted November 26, 2006 getcwd is not a module available on the server. I did try $ENV{"PWD"} though - and that seemed to work. Quote
flamey Posted November 26, 2006 Author Posted November 26, 2006 thanks for replys. getcwd is not a module available on the server. actually getcwd() is a method of CWD module which is installed. however getcwd() returned me the same thing $ENV{PWD} contains, which is "/home/myaccount". and abs_path("myscript.pl") returned "/home/myaccount/myscript.pl" - which is NOT true, the path to the script is /home/myaccount/public_html/cgi-bin/whateverfolder/myscript.pl i guess it is better then nohting, it will help if i ever need to move to another hosting, but will not if i move or rename the script. i do appreciate the help, if you can think of anything else that can help me in this, please post if here. i went though all environmental variables available while running as a cron, the following are devined: HOME - /home/accountname LOGNAME SHLVL MAILTO PATH (not what i need) SHELL PWD - /home/accountname USER Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.