0

I have the following script to update the price, stocks and thereafter refresh the cache.
File: /var/scripts/update-web.sh

#!/bin/bash
echo "$(date)"
echo "\n"
echo ======================= Updating Prices ======================="
source /var/scripts/update-prices.sh

echo "$(date)"
echo "\n"
echo ======================= Updating Stocks ======================="
source /var/scripts/update-stocks.sh

echo "$(date)"
echo "\n"
echo "======================= Refreshing cache ======================="
# @todo - This script should be run as root user after updating prices & stocks
source /var/scripts/clear-cache.sh

echo "$(date)"
echo "\n"
echo "[COMPLETED]"

This script is run as www-data user from crontab

sudo crontab -u www-data -e

with the following crontab entry:

1 0 * * * /var/scripts/update-web.sh > /tmp/update-web.txt

My main problem here is to run the /var/scripts/clear-cache.sh script as root user (immediately after updating prices & stocks).
Let me know if there's a workaround for this.

1

Instead run the www script from a root script

#!/bin/sh
su www-data -c /var/scripts/update-web.sh
/var/scripts/clear-cache.sh

Make a script like that and run it from root's crontab, and remove the entry from www-data's crontab.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.