doueta6642 2014-07-29 22:15 采纳率: 0%
浏览 29
已采纳

Cron使缓存文件不可写

I have a cron job that I've set up to run every five minutes. Because this cron job is not being run through apache, I believe if it ends up touching the website's server-side cache files (which it does frequently), that those cache files end up no longer being writable by apache, and so I get all these errors about not being able to write to the cache files every time I run the website in the browser. Is there any way I can get it to not have this problem? Running the website on Centos 6.4, in case that's relevant.

  • 写回答

1条回答 默认 最新

  • douhui9380 2014-07-29 22:27
    关注

    There are at least two solutions to this problem, both involve using chmod and chown.

    Solution 1:

    Move whatever your cronjob runs into its own shell script, and tell cron to run your shell script instead.

    After your original command runs, run chmod and chown to change the permissions as you want.

    #!/bin/sh
    printf "Do your stuff here
    "
    DIR_ROOT="./your-dir-here/"
    find $DIR_ROOT -type f -print0 | xargs -0 chmod 664 # make all files user+group r+w
    find $DIR_ROOT -type d -print0 | xargs -0 chmod 775 # make all directories user+group r+w+x
    chown apache:apache -r $DIR_ROOT
    

    Solution 2:

    Instead of using a shell script, you could append a semicolon to the command your cronjob runs, and then add chmod and chown.

    */5 * * * * /my/five/minute/script.sh; chmod 664 ./some-file; chown apache:apache ./some-file
    

    Hope that helps.

    Note: Both solutions are intentionally not the same, I want you to try to think your way through this.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?