freeloader Posted November 11, 2006 Share Posted November 11, 2006 Hi guys,I have a linux installation (mandrake 8) using LAMP running a little home server. I created a second user account for telnet / SSH access besides the root. I logged into the server from myo other pc using Putty. Edited the crontab using crontab -e. Checked uo with crontab -l and it was installed. The file I ran the conjob for was crontest.php.Content crontest.php:[code]<?phpwritefile("logs/ITWORKS.txt","TEST");function writefile($file,$text) {$Handle = fopen($file, 'a');$Data = "$text\n";fwrite($Handle, $Data);fclose($Handle); }?>[/code]This is what I got as return result in my mailbox:[code] Warning: fopen(logs/ITWORKS.txt): failed to open stream: No such file or directory in /opt/lampp/htdocs/crontest.php on line 7 Warning: fwrite(): supplied argument is not a valid stream resource in /opt/lampp/htdocs/crontest.php on line 9 Warning: fclose(): supplied argument is not a valid stream resource in /opt/lampp/htdocs/crontest.php on line 10 [/code]I checked and the chmod preferences for /logs are at 777.Can anybody help me figure out what went wrong?Thanks in advance. Quote Link to comment Share on other sites More sharing options...
doni49 Posted November 11, 2006 Share Posted November 11, 2006 Take a look at line 7. You're specifying a RELATIVE path in the filespec. But to WHAT directory it relative? Try putting a FULL PATH.The other error lines pop up because $Handle doesn't contain a usable file resource. Quote Link to comment Share on other sites More sharing options...
freeloader Posted November 11, 2006 Author Share Posted November 11, 2006 I'll try that out, but the file works when I load it just in my browser... Only when using cron it gives error. Quote Link to comment Share on other sites More sharing options...
doni49 Posted November 11, 2006 Share Posted November 11, 2006 [quote author=freeloader link=topic=114595.msg466300#msg466300 date=1163208866]I'll try that out, but the file works when I load it just in my browser... Only when using cron it gives error.[/quote]That's probably because relative to the URL of your current page, the file location is fine. But I'm not sure what folder a cron job would run from--PROBABLY the root of your area (not the web root).BTW when I said "full path" earlier, I didn't mean a full URL (http://www.mydomain/logs/ITWORKS.txt). I meant a full server path (/home/username/public_html/logs/ITWORKDS.txt--this example is JUST an example. What you need to put will depend on your specific server configuration).Good luck! Quote Link to comment Share on other sites More sharing options...
freeloader Posted November 11, 2006 Author Share Posted November 11, 2006 Still doesn't work when using full path. Is that really the only thing that could've went wrong.Maybe I should use full path on the HD like e:\linux\opt\ .. ?This is what crontest.php looks like now:[code]<?phpwritefile("/opt/lampp/htdocs/logs/ITWORKS.txt","TEST");function writefile($file,$text) {$Handle = fopen($file, 'a');$Data = "$text\n";fwrite($Handle, $Data);fclose($Handle); }?>[/code] Quote Link to comment Share on other sites More sharing options...
doni49 Posted November 11, 2006 Share Posted November 11, 2006 I didn't think linux used drive letters (e:). Also doesn't it have to be a FRONT slash (/)? Quote Link to comment Share on other sites More sharing options...
freeloader Posted November 11, 2006 Author Share Posted November 11, 2006 I edited my previous post, can you have a look at the new content of crontest.php? Quote Link to comment Share on other sites More sharing options...
doni49 Posted November 11, 2006 Share Posted November 11, 2006 That's the only thing that I see.Try putting the putting the following in a file by itself and load it in your browser.[code]<?phpphpinfo();?>[/code]Look for a line that says [b]DOCUMENT_ROOT[/b]. Now does it say [b]/opt/lampp/htdocs/[/b]? If yes, then that fixes THAT part and there must be some other problem too. Quote Link to comment Share on other sites More sharing options...
freeloader Posted November 11, 2006 Author Share Posted November 11, 2006 DOCUMENT_ROOT /opt/lampp/htdocsAny ideas what the other problem might be? Quote Link to comment Share on other sites More sharing options...
freeloader Posted November 12, 2006 Author Share Posted November 12, 2006 * bump *any answers yet? Quote Link to comment Share on other sites More sharing options...
doni49 Posted November 13, 2006 Share Posted November 13, 2006 The only other possiblity that [b]I[/b] can see is that maybe the file doesn't exist (remember *nix filesystem is case sensitive--ITWORKS.txt isn't the same as itworks.txt. Or there is a problem with your permission settings.Try this above the call to your function:if(file_exist("/opt/lampp/htdocs/logs/") && is_dir("/opt/lampp/htdocs/logs/")){ dir("/opt/lampp/htdocs/logs/")}else{ echo "Folder missing"; dir("/opt/lampp/htdocs/")} Quote Link to comment Share on other sites More sharing options...
lead2gold Posted November 13, 2006 Share Posted November 13, 2006 also... the cronjob will execute using your usernameMake sure if you want to write in the /opt folder you do the cronjob -e as root.Otherwise pick a home directory to run your test in.such as "~/temp.log" Quote Link to comment Share on other sites More sharing options...
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.