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.<br /><br />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?<br /><br />thanks in advance!<!--content-->
Hi Flamey,<br /><br />I don't think you can in perl, I think you need to tell it the directory you want it writing to.<!--content-->
You can <a href="http://kobesearch.cpan.org/htdocs/perl/Cwd.html" target="_blank">try one of these methods</a>.<!--content-->
getcwd is not a module available on the server. <br /><br />I did try $ENV{"PWD"} though - and that seemed to work.<!--content-->
thanks for replys.<br /><br /><!--quoteo--><div class='quotetop'>QUOTE</div><div class='quotemain'><!--quotec-->getcwd is not a module available on the server.<!--QuoteEnd--></div><!--QuoteEEnd--><br />actually getcwd() is a method of CWD module which <i>is</i> installed.<br />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<br /><br />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.<br /><br />i do appreciate the help, if you can think of anything else that can help me in this, please post if here.<br /><br />i went though all environmental variables available while running as a cron, the following are devined:<br /><br />HOME - /home/accountname<br />LOGNAME<br />SHLVL<br />MAILTO<br />PATH (not what i need)<br />SHELL<br />PWD - /home/accountname<br />USER<!--content-->
Hi Flamey,<br /><br />I don't think you can in perl, I think you need to tell it the directory you want it writing to.<!--content-->
You can <a href="http://kobesearch.cpan.org/htdocs/perl/Cwd.html" target="_blank">try one of these methods</a>.<!--content-->
getcwd is not a module available on the server. <br /><br />I did try $ENV{"PWD"} though - and that seemed to work.<!--content-->
thanks for replys.<br /><br /><!--quoteo--><div class='quotetop'>QUOTE</div><div class='quotemain'><!--quotec-->getcwd is not a module available on the server.<!--QuoteEnd--></div><!--QuoteEEnd--><br />actually getcwd() is a method of CWD module which <i>is</i> installed.<br />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<br /><br />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.<br /><br />i do appreciate the help, if you can think of anything else that can help me in this, please post if here.<br /><br />i went though all environmental variables available while running as a cron, the following are devined:<br /><br />HOME - /home/accountname<br />LOGNAME<br />SHLVL<br />MAILTO<br />PATH (not what i need)<br />SHELL<br />PWD - /home/accountname<br />USER<!--content-->