Question

We run a CentOS WHM/cPanel VPS with ~230 clients most of who use our own CMS software. The software has built in versioning and updates, but for various reasons this isn't activated on a portion of our sites, and as such I can't use it for the update I'm wanting to push out.

I'm looking for some way to take a new (in this example) updates.php from one location, and replace any other updates.php that exist at public_html/admin/updates.php for each user on the server.

The file that needs updating is at the same relive path (i.e. /home/[USERNAME]/public_html/admin/updates.php) for every user on the VPS who has it. Obviously thus any user who doesn't have it needs to be skipped (to avoid creating updates.php files all over the place.

Our PHP is also setup to run under SuExec, so I can't simply write a PHP script and run it - so assuming it'll need to be through shell of some kind - which is absolutely not something I'm good at. That said, I do have root access so can do anything there as required.

Love to hear your ideas/solutions, and obviously happy to answer any questions.

Was it helpful?

Solution

Write a shell script like this

for i in /home/* ; do
  if [ -d "$i" ]; then
    echo "found $i"
          if [ -f "$i/public_html/admin/updates.php" ]; then
            cp /home/updates.php $i/public_html/admin/updates.php
          fi
  fi
done

First if checks for directory, i.e. check for all the user directories. Then within each directory check whether the updates file exists. If it does, copy the file /home/updates.php (where you should put yours) there.

Edit: Put the code in a file applyUpdate.sh, use chmod +x applyUpdate.sh to make it executable and then run it using ./applyUpdate.sh

OTHER TIPS

If the name of this file is upgrade.php, and that's the only upgrade.php you have on your user directory, consider using this:

find /home/ -name upgrade.php -exec cp -p /path/to/new_upgrade {} \;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top