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/ /var/www/vhosts/

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
cp -a /var/www/vhosts/ /var/www/vhosts/${dstdir}/httpdocs/

Or, on one single line if needed (careful with the ";"):
for dstdir in; do cp -a /var/www/vhosts/ /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 ( and 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.

Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

pmagonyAuthor Commented:
By the way, I have another question related to this project I'm working on over here... 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/ /var/www/vhosts/

Tested and works.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.