I'm following youtube videos and online courses, learning about Linux command, enhancing skills, trying to get good. Currently trying to understand scheduling.
My Raspberry Pi is running owncloud on headless Raspbian. I want to schedule it to put owncloud in to maintenance mode, apt-get update then apt-get upgrade, then take owncloud out of maintenance mode, once a week. Owncloud (php) commands should be issued from user www-data, whereas apt-get should be run as root. So far, I've tried this:
sudo -u www-data crontab -e
Adding the line
0 7 * * 1 php /var/www/owncloud/occ maintenance:mode --on
sudo crontab -e
1 7 * * 1 apt-get update && apt-get upgrade -y
But here I get stuck. How do I tell the system to bring owncloud out of maintenance mode after apt-get upgrade -y returns exit status 0? I thought about making the entry in root's crontab as
1 7 * * 1 apt-get update && apt-get upgrade && php /var/www/owncloud/occ maintenance:mode --off
but maintenance:mode --off fails as it isn't run by user www-data. I could schedule the last command to run minutes later as www-data but I'd rather it run when apt-get upgrade -y gives exit status 0. Is there a way of doing this?