User write access

Whether you are using Linux on the desktop or as a server, it's still good that you're using Linux. Linux related questions go here.

Moderator: General Moderators

User avatar
kbrown3074
Forum Contributor
Posts: 119
Joined: Thu Jul 20, 2006 1:36 pm

User write access

Post by kbrown3074 »

I am having a problem with pages I am trying to have run thru a cron job. I can run the pages via the webpage itself, but thru a command line on the server it does not work. There is a similiar job running on a different directory and it works fine. The directory access is the same on both directories. Both directories only have root as the user. I know there is something Im missing..just not sure what to check.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

cron jobs will run as root, whilst when you view them in your browser, they will run as the webserver's user, not root.
User avatar
kbrown3074
Forum Contributor
Posts: 119
Joined: Thu Jul 20, 2006 1:36 pm

Post by kbrown3074 »

My problem is that for some reason I cant get the new shell script to create files in the new directory. The existing script works fine and the directory has the same read/write attributes. I am getting the below error while trying to write to the directory thru the command line

Code: Select all

Can't create/write to file '/var/www/htdocs/daily_edts/sheets/2007_05_14_treeleads.txt' (Errcode: 2)
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

what's the output of:

Code: Select all

ls -l /var/www/htdocs/daily_edts/sheets/2007_05_14_treeleads.txt
User avatar
kbrown3074
Forum Contributor
Posts: 119
Joined: Thu Jul 20, 2006 1:36 pm

Post by kbrown3074 »

nothing..file doesnt exist
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

output of:

Code: Select all

ls -l /var/www/htdocs/daily_edts/sheets/
?
User avatar
kbrown3074
Forum Contributor
Posts: 119
Joined: Thu Jul 20, 2006 1:36 pm

Post by kbrown3074 »

Code: Select all

root@seq2:~# ls -l /var/www/htdocs/daily_reports/sheets
total 404
-rw-r--r-- 1 root root  9728 2007-05-13 06:55 aaasj2007-05-13.xls
-rw-r--r-- 1 root root 14848 2007-05-13 06:55 Cobra2007-05-13.xls
-rw-r--r-- 1 root root  5632 2007-05-13 06:55 confirmobleads2007-05-13.xls
-rw-r--r-- 1 root root  6144 2007-05-14 06:55 confirmobleads2007-05-14.xls
-rw-r--r-- 1 root root 11264 2007-05-10 09:15 cont66ib2007-05-10.xls
-rw-r--r-- 1 root root 12800 2007-05-13 06:55 cont66ib2007-05-13.xls
-rw-r--r-- 1 root root 21504 2007-05-13 06:55 cont66ob2007-05-13.xls
-rw-r--r-- 1 root root  4096 2007-05-13 06:55 cont66obleads2007-05-13.xls
-rw-r--r-- 1 root root  8704 2007-05-14 06:55 cont66obleads2007-05-14.xls
-rw-r--r-- 1 root root  4096 2007-05-13 06:55 cont66pt2007-05-13.xls
-rw-r--r-- 1 root root  5120 2007-05-14 08:14 cont66pt2007-05-14.xls
-rw-r--r-- 1 root root 39936 2007-05-13 06:55 dtree2007-05-13.xls
-rw-r--r-- 1 root root 12800 2007-05-13 06:55 gwoeib2007-05-13.xls
-rw-r--r-- 1 root root 20480 2007-05-13 06:55 gwoeob2007-05-13.xls
-rw-r--r-- 1 root root  4096 2007-05-13 06:55 gwoeobleads2007-05-13.xls
-rw-r--r-- 1 root root  4096 2007-05-14 06:55 gwoeobleads2007-05-14.xls
-rw-r--r-- 1 root root  4096 2007-05-13 06:55 gwoept2007-05-13.xls
-rw-r--r-- 1 root root  5120 2007-05-14 08:14 gwoept2007-05-14.xls
-rw-r--r-- 1 root root 13312 2007-05-13 06:55 ibcib2007-05-13.xls
-rw-r--r-- 1 root root 20480 2007-05-13 06:55 lifesec2007-05-13.xls
-rw-r--r-- 1 root root 12288 2007-05-13 06:55 ltcib2007-05-13.xls
-rw-r--r-- 1 root root  9216 2007-05-13 06:55 ltcny2007-05-13.xls
-rw-r--r-- 1 root root 21504 2007-05-13 06:55 ltcob2007-05-13.xls
-rw-r--r-- 1 root root 12288 2007-05-14 07:51 medsupib2007-05-14.xls
-rw-r--r-- 1 root root 21504 2007-05-14 07:51 medsupob2007-05-14.xls
-rw-r--r-- 1 root root 22528 2007-05-13 06:55 mhip2007-05-13.xls
-rw-r--r-- 1 root root 12800 2007-05-13 06:55 partdib2007-05-13.xls
-rw-r--r-- 1 root root 21504 2007-05-13 06:55 partdob2007-05-13.xls
root@seq2:~#
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

ok, I'm going to assume that the directory itself is set for root:root 0644; which would prohibit any user but root from writing to that directory.

You can either change the group ownership to that of the same group as your webservers user and chmod to 0664, or chmod the directory to 0666 which will allow anyone to write (but not execute) the files - I recommend the former.
User avatar
kbrown3074
Forum Contributor
Posts: 119
Joined: Thu Jul 20, 2006 1:36 pm

Post by kbrown3074 »

not exactly sure how I would modify the user group. How would I go about doing that?
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

User avatar
kbrown3074
Forum Contributor
Posts: 119
Joined: Thu Jul 20, 2006 1:36 pm

Post by kbrown3074 »

I guess I am completely missing the boat on this one. I thought there would be more than 1 group when I do a groups command..not the case. Seems like something simple to allow the root user to write files to this dir..but it still isnt working...ugh!

Code: Select all

root@seq2:/var/www/htdocs/daily_edts/sheets# groups
root
root@seq2:/var/www/htdocs/daily_edts/sheets#
root@seq2:/var/www/htdocs/daily_edts/sheets# users
root root
root@seq2:/var/www/htdocs/daily_edts/sheets#
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

have you confirmed your webserver is running as root? It is a) unlikely and b) a bad idea
User avatar
kbrown3074
Forum Contributor
Posts: 119
Joined: Thu Jul 20, 2006 1:36 pm

Post by kbrown3074 »

I am not sure..I didnt set it up. I just ssh into it as root. How would I check to see if it is actually running as root?

BTW...if I run the pages that create an xls by itself from the browser, it creates the file. If I run the edts.php that calls all the other pages, nothing gets created.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

Ok, before I get anymore muddled.. are you trying to write to the file(s) with your cron job, or from the webserver (prompted by browsing to page in your browser?)
User avatar
kbrown3074
Forum Contributor
Posts: 119
Joined: Thu Jul 20, 2006 1:36 pm

Post by kbrown3074 »

I want to be able to do it through the cron job.
Post Reply