Jump to content

Writing To File While Running As A Cron Job?


Recommended Posts

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!

Link to comment
Share on other sites

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




PATH (not what i need)


PWD - /home/accountname


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...