• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1314
  • Last Modified:

Plesk Cron Job - How To


I need to take a file from one website, and copy it over to several other sites on the same server.  The file in question is owned by the web user.  How can I complete such a task through the scheduler in Plesk?  

I attempted to use the following but it is only applicable for 1 website and it fails with a "stat permission denied":
cp /var/www/vhosts/domain.net/httpdocs/catalog.txt.gz /var/www/vhosts/other-domain.org/httpdocs/

Open in new window

  • 4
  • 3
  • 2
1 Solution
I'm not familiar to plesk. But it seems to be some usual permission problem.
Some ideas:

1) check the file permission (and directories above)
2) check the destination directory permission
3) which user is running the cp command?
4) you might use "cp -a" instead of "cp" to keep permissions, date/time on the destination file
5) when it works for one, you might make a loop of your command:
for dstdir in my.2nd.domain.org      my.3rd.com       another.one.net
cp -a /var/www/vhosts/domain.net/httpdocs/catalog.txt.gz /var/www/vhosts/${dstdir}/httpdocs/

Or, on one single line if needed (careful with the ";"):
for dstdir in my.2nd.domain.org      my.3rd.com       another.one.net; do cp -a /var/www/vhosts/domain.net/httpdocs/catalog.txt.gz /var/www/vhosts/${dstdir}/httpdocs/; done

I hope it helps

You will have a problem acheiving this due to file permissions. Even though both webusers (user1@domain.net and user2@other-domain.org) are both in the 'psacln' group you will discover that permissions are not set for correctl;y for the httpdocs folder. All httpdocs are set by default to rwxr-w---- (750) and is owned by 'psaserv' not psacln.

If you want to allow members of the group to write to that folder then you will need to set the write bit for the group, by making it rwxrwx--- (chmod 770 httpdocs) and also change the group to psaserv (chown user2.psacln httpdocs) to allow user1 to write to the web folder of user2.

Then just create a batch job as mchkorq demonstrated above then test the batch job from the command line to verify all is good. Use the 'scheduled tasks' in user1's control panel to run the job as often as you want.

If you need further advice with scheduling the job via the control panels - let us know what version of plesk your running and I'll talk you through it.

If you have problems running the task via the crontab but it's ok on the command line then their maybe a problem with SELinux... Just post the errors and we'll solve them for you.

Good luck.

pmagonyAuthor Commented:
Thanks for taking the time to respond.  I must say, some of this is well over my head.

@szlamp:  I'm not sure i feel comfortable setting permission changes to httpdocs.  Is there an alternate folder above the httpdocs that's more user/permission independent and that could be used to copy the file to and then run a cron job by the web user for each respective site to grab it and move it to its httpdocs space?

@mchkorq: what is ${dstdir}?  Is that like a variable that holds the name/path of each site folder and then in your cp line you simply loop through it?  Sounds promising!

The other solution is for me to simply have the catalog file ftp'd daily to each site, and then set up a cron for each site user like i have now for the current site.  It's longer approach but will work.

Build your data science skills into a career

Are you ready to take your data science career to the next step, or break into data science? With Springboard’s Data Science Career Track, you’ll master data science topics, have personalized career guidance, weekly calls with a data science expert, and a job guarantee.

pmagonyAuthor Commented:
By the way, I have another question related to this project I'm working on over here... http://www.experts-exchange.com/Q_25591288.html maybe you guys can assist?
the 'private' folder is basically what your looking for then. That's just a storage room for files to do with the web site being hosted that aren't to be made publically available. I use it to store scripts and things related to the website. That should do the job nicely.
pmagonyAuthor Commented:
Yes, but can I cron files from one sites private folder to another sites private folder and bypass all these owner/permission issues?
I'll explain the loop. Uppercase words are part of the syntax. The rest is variable. In real life, these uppercase words must be written in lowercase, as shell scripts (and everything in Linux) are case-dependent.

FOR whatever_variable_name IN a bunch of values or 1 2 3 numbers
#something, example:
echo ${whatever_variable_name}
echo $whatever_variable_name is possible, too. But sometimes brackets are needed

It'll result in "echo"ing (writing to the terminal):

So in my example, if you're able to cp your file - I mean, if you fix that permission/ownership problem - the loop will help you copy your file over your different web sites in one single scheduled script.

ooops, I wrote "cp -a" in my command, but it'll recreate the irectory structure, I guess.
Use "cp -p" to presever permissions.

Hi PMAgony, :-)

I don't mean to sound funny hear but I can't find any other weay of saying this tactfully, so here goes: You will still need to change permissions to allow a different user to write to any folder. Linux is not windows, it's much more secure as I am sure you're aware and simply wont allow other users to read, write or execute files that belong to other users without permission to do so, like windows does. There is no way around this -- at some level, at some point you are going to have assign permissions to something so it can operate on both user accounts.

If you have issues with modding the permission for system folders then why not simpyl make a sub directory and use that?

ie. ./httpdocs/shared/

Then run:

chmod 770 ./httpdocs/shared
chown <user>.psacln ./httpdocs/shared

That may be the best comprimise you are going to get.
pmagonyAuthor Commented:
Thanks for all the feedback guys.  I contacted my host, and he pointed me to the Home page in plesk.  The home page in Plesk has a global scheduled tasks feature that allows you to run Cron jobs as any system user, including root.  Very nice feature.

The end result was creating a scheduled task as ROOT and that command was as follows:

cp -p /var/www/vhosts/domain.net/httpdocs/catalog.txt.gz /var/www/vhosts/other-domain.org/httpdocs/

Tested and works.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

A proven path to a career in data science

At Springboard, we know how to get you a job in data science. With Springboard’s Data Science Career Track, you’ll master data science  with a curriculum built by industry experts. You’ll work on real projects, and get 1-on-1 mentorship from a data scientist.

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now