I'm having a little issue reading a file into my perl scripts while using cron. I have a small text file that stores two lines of text. I have a perl script that needs to read in this text. Here's the code I use:
open(TICKS,"textfile");
while(<TICK>){
$thestring=$_;
}
print $thestring;
I have my perl script execute automatically each night using cron. However, whenever cron runs the script, it never is able to read in the text from the file. No errors are reported, the file is just read. Each night I check my computer to find that the script has not read the file. I then manuall run the script and it reads the file just fine.
I having trouble determining what is wrong. Could this be a permissions issue. Cron is run as root, right? When I run the script manually it is as root as well. Is it possible that running the script a second time successively does the trick? If I run the script manually after cron runs it, it reads the text file fine even though it didn't when run through cron.
Thoughts?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.