Running Diskutility to repair permissions using cron

Discussion in 'General Mac Discussion' started by dudeami, Mar 12, 2004.

  1. dudeami macrumors regular

    Feb 4, 2004
    I am waiting for my Mac to finish defragmenting my hard drive, anyway I was humming a tune and it turned into this.

    Run slow, sweet defragment
    running fore to optimize disks....

    Seriously. I haven't really coded anything since my college days, and never scripted for Unix. But I hate automating things that can grow forever. I have seen many people discussing using crontab to run weekly permission repairs, but they all seem to append to the same document. I have been testing this script, which I believe should not allow this to grow forever, but keep at least a month of activity logged. Does this look good. Any suggestions on how to improve it. Problems with text wrapping so I am spacing out the if statements for readability.


    #!/bin/sh -


    if [ -x /usr/bin/gzip ]; then gzext=".gz"; else gzext=""; fi

    cd /var/log

    if [ -f "dskrpr.log.3${gzext}" ] ; then rm "dskrpr.log.3${gzext}" ; fi

    if [ -f "dskrpr.log.2${gzext}" ] ; then mv -f "dskrpr.log.2${gzext}" "dskrpr.log3.${gzext}" ; fi

    if [ -f "dskrpr.log.1${gzext}" ] ; then mv -f "dskrpr.log.1${gzext}" "dskrpr.log.2${gzext}" ; fi

    if [ -f "dskrpr.log.0${gzext}" ] ; then mv -f "dskrpr.log.0${gzext}" "dskrpr.log.1${gzext}" ; fi

    if [ -f "dskrpr.log" ] ; then cp -pf dskrpr.log dskrpr.log.0 ; if [ -x /usr/bin/gzip ]; then gzip -9 dskrpr.log.0; fi ; fi

    echo Repair Permissions log files successfully rotated > /var/log/dskrpr.log

    echo `date` Beginning the repair of system permissions >> /var/log/dskrpr.log

    diskutil repairPermissions / >> /var/log/dskrpr.log

    echo `date` Finished >> /var/log/dskrpr.log


  2. dudeami thread starter macrumors regular

    Feb 4, 2004
    By the way, if you are interested in trying this out, and don't have much experience in the shell. Here is what I have done.

    Do this at your own risk. I have not had a single problem. Make sure that the script doesn't wrap lines or anything weird. You may have to expand the pico window when entering the script. Hopefully some others can verify the soundness of the script.

    1. created a file for my eample on the root, it probably can be somewhere else, but this is where I put it when testing. I'll just refer to it as filename

    2. Enter/Paste the commands into the file and save it.

    3. In terminal go to path of file. In this example. cd /

    4. sudo chmod 744 filename
    (to make the file executable.)

    5. cd /etc

    6. sudo cp crontab crontab.bak
    (to back up your crontab file)

    7. sudo pico crontab
    (to schedule the script)

    8. in pico use the arrow keys to get to the empty line below other last scheduled task.

    9. 30 8 * * 5 root /filename
    This would schedule this script to run at 8:30 AM every Friday using root.
    While you are here you can reschedule the daily, weekly and monthy maintenance tasks to run when you know that your computer will be awake.

    10. in pico enter control-o to write out the file. Then hit enter to use the name crontab.

    11. in pico enter control-x to exit pico.

    12. If you want to test it manually. In the terminal run sudo /filename

    13. To see activity, you can use the activity monitor. When the disk utility is done, you can check the log file from terminal by typing open /var/log/dskrpr.log

Share This Page