|
|
#1 | |||||||||||||||||||
|
Major Leaguer
Join Date: Jan 2002
Posts: 311
|
Daily Scripts - how to make them fix permissions?
Now that Panther's energy saver offers the ability to run a scheduled wake-up, it seems I no longer need to use Xjanitor to do this while my computer is awake, but can actually schedule my laptop to wake up and run the scripts at night! (I assume I must have my laptop open for this to work.) However, I have a question regarding how to get the daily script fix my "permissions" which seems to be a good practice. I looked at the comments in this hint and saw what seemed like an excellent solution:
My problem is that I can't find daily.local anywhere! I found a script called daily, which supposedly calls daily.local - but I did a search (including invisible files) and simply couldn't find daily.local. The only thing I found was something in the etc/periodic folder called 500.daily. I don't want to mess anything up, so when things aren't excactly as described in a hint like this I'd rather not experiment unless someone more knowledgable than myself can help. Thanks! |
|||||||||||||||||||
|
|
|
|
|
#2 |
|
Triple-A Player
Join Date: May 2003
Location: Atlanta GA US
Posts: 134
|
Understandable. The file daily.local probably does not exist yet. The relevant code from the daily crontask is:
Code:
if [ -f /etc/daily.local ]; then
echo ""
echo "Running daily.local:"
sh /etc/daily.local
fi
Two other considerations: 1) do you really want to repair permissions every day? This may overkill, although I wouldn't think it would hurt anything. You could do it in the weekly.local script (similar setup). 2) Doing it this way will not give you any text output; and it is often helpful to know what permissions needed fixing. A simple approach to this issue is to modify your script as follows: Code:
diskutil repairPermissions / > ~/Desktop/permsFixed.txt
__________________
MacBook 2 GHz Intel CoreDuo; 2GB RAM; 10.4.X. |
|
|
|
|
|
#3 |
|
Major Leaguer
Join Date: Jan 2002
Posts: 311
|
Doing it weekly makes sense.
Now I'm trying to figure out how to optimize things so that my computer doesn't stay awake for too long. The default Cron settings seem to have the daily set for 3:15, the weekly for 4:30 and the monthly for 5:30. Now, I'd like to wake my computer at 3:00 am, but keep the sleep settings so that my computer goes to sleep after an hour of inactivity. How should I set the Cron tasks so that these scripts will all run within that time frame, but not cause any conflicts? |
|
|
|
|
|
#4 |
|
Triple-A Player
Join Date: May 2003
Location: Atlanta GA US
Posts: 134
|
Do you mean that when cron runs these tasks, that is considered idle time by the power management function? I (apparently mistakenly) figured that the sleep timer setting wouldn't kick in until after the crontasks were finished. Guess I can't help on this ... but a few minor thoughts:
1) If you don't relish the idea of editing crontabs at the commandline yourself, try a GUI front-end to do this like Cronnix . 2)Some tasks included by the system in the crontasks may not be needed by you. Their exclusion could save time in the execution of the crontasks and make it easier to juggle timeslots. For example, I do not use the locate commandline utility and have excluded from the weekly crontask the job of updating its database (saves like 15 or 20 minutes - see this old thread if you care about this - it's really a minor point I guess.
__________________
MacBook 2 GHz Intel CoreDuo; 2GB RAM; 10.4.X. |
|
|
|
|
|
#5 |
|
Major Leaguer
Join Date: Jan 2002
Posts: 311
|
Yes, I depend on Cronnix - a great app!
Not sure about Locate however. I used to love using the Locate GUI for OS X, however, with the improved Panther find performance (at least it seems better to me), I may not use locate anymore ... I'll have to think about it. As with the other things - I don't mind running all of these while I sleep. The issue is just a matter of timing. If one cron task has ended and it takes over an hour before the next one starts, it won't start. On the other hand, is there any problem associated with running all of them at the same time? |
|
|
|
|
|
#6 |
|
MVP
Join Date: Jan 2002
Posts: 1,562
|
I used to have as script exactly like you are talking about - repaired permissions every night. Then on a completely unrelated topic regarding maxvnodes I was reading at Apple discussions, there was some talk about items like daily, and any other scripts that basically open or touch 1000's of files. Jest of it was - this type of action causes your vnodes to max out. Not sure exactly what the whole vnode thing is about as its a bit deep, but I can say that in monitoring my vnodes I find my old G4/400 runs much better when the vnodes are not maxxed out and I can also tell you that my "repair permissions" script would peg the vnodes at 100% every time so I discontinued using it.
|
|
|
|
|
|
#7 |
|
Major Leaguer
Join Date: Dec 2002
Posts: 291
|
First off, I rescheduled my scripts to run while my computer would normally be awake - between the hours of 9 and 10 pm. It does slow things down a bit, but not so that it is unacceptable. However, if you did want the computer to return to sleep at the completion of a script, you could add a final line:
Code:
osascript -e 'tell application "Finder" to sleep' |
|
|
|
|
|
#8 |
|
Major Leaguer
Join Date: Jan 2002
Posts: 311
|
The sleep command is useful, but I don't want to change my default Engery saver sleep settings to not sleep. I like having my iBook sleep whenever I'm not using it. So I just want to make sure that it gets the job done before sleeping - rather than making sure it sleeps when done...
|
|
|
|
|
|
#9 | |||||||||||||||||||
|
Major Leaguer
Join Date: Jan 2002
Posts: 311
|
I initially tried running the script this way, and it gave me an error message telling me that "permsFixed.txt" didn't exist. So, I thought: why create a new file when I already have the /var/daily.out log file to write things to. This sort of worked, but it seems to have over-written the beginning of the document, rather than appended the repairPermissions output to the end of the log. Is there some way to change this command so that it appends the output to the end of /var/daily.out instead of overwriting the document? Thanks! |
|||||||||||||||||||
|
|
|
|
|
#10 |
|
MVP
Join Date: Jan 2002
Posts: 1,562
|
Change the ">" to a ">>"
|
|
|
|
|
|
#11 | |||||||||||||||||||
|
Major Leaguer
Join Date: Jan 2002
Posts: 311
|
Thanks! (That was easy...) here is what I have now: Code:
diskutil repairPermissions / >> /var/log/daily.out The only other thing I had to do was to adjust the energy saver settings to startup the iBook (which is usually just sleeping) at 3:00am and sleep after an hour of inactivity. Then I set the Cron tab for the periodic tasks to run between 3 and 4 (daily, weekly, and monthly, accordingly). I'll post back if there are any problems that arise, but it seems to work. |
|||||||||||||||||||
|
|
|
|
|
#12 |
|
Triple-A Player
Join Date: May 2003
Location: Atlanta GA US
Posts: 134
|
Very neat, Kerim - a nice solution. I'm sorry my output suggestion didn't work as written for you. It does for me. When I use output redirection in this manner, if the target file does not exist then it is created. I run the script manually and perhaps it behaves differently when cron is running the show. Ya taught me something here.
Anyway, now that I have finally installed Panther, I think I'll make use of your approach - thanks!
__________________
MacBook 2 GHz Intel CoreDuo; 2GB RAM; 10.4.X. |
|
|
|
|
|
#13 | |||||||||||||||||||
|
Major Leaguer
Join Date: Jan 2002
Posts: 311
|
It is working, but the daily.out log is still a little strange. Here is what I mean:
Do you see where the disk utility data is? Shouldn't it be at the end of the log? Not that it matters that much, but I'm curious. At least today there were no permissions to be fixed - which is a first. Perhaps 10.3.1 fixed something? |
|||||||||||||||||||
|
|
|
|
|
#14 |
|
Prospect
Join Date: Jan 2002
Location: Eugene
Posts: 25
|
unnecessary output redirection
My /etc/daily.local script on Jaguar:
Code:
echo "" echo "Repairing disk permissions" nice diskutil repairPermissions / echo "Fixing sendmail permissions" chmod 2555 /usr/sbin/sendmail echo "" Code:
% grep daily_output /etc/defaults/periodic.conf daily_output="/var/log/daily.out" # user or /file |
|
|
|
|
|
#15 |
|
MVP
Join Date: Jan 2004
Posts: 1,764
|
Automating repairpermission on Panther -continued discussion after 8 months
Hi all, I have been reading the post on using cron to automate repair permission, but I am unable to get it to run on my machine so I am here for some help. Here is what I have so far.
I created this code and named it daily.local as shown below: Code:
# This script will run daily automatic repair permission that will be called by periodic/daily/500.daily diskutil repairPermissions / >> /Users/ronaldcross/Desktop/repairpermission.txt Code:
if [ -f /etc/daily.local ]; then
echo ""
echo "Running daily.local:"
sh /etc/daily.local
fi
Do I need to put #!/bin/sh in daily.local to get it to work? Do I need to put sudo diskutil repairPermissions / >> /Users/ronaldcross/Desktop/ in daily.local ? Yes, daily.local is executable with 755 file permission. thx RLC |
|
|
|
|
|
#16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Prospect
Join Date: Jan 2002
Location: Eugene
Posts: 25
|
No; it's explicitly run with sh.
The /etc/daily.local script runs as root so no "sudo" is necessary.
The full pathname of your script is /etc/daily.local ? As before, permissions don't matter because it's explicitly run with sh. In a Terminal shell, run: zgrep periodic /var/log/system.log.0.gz ... and look for a line like: Jul 27 03:15:00 hostname CRON[16066]: (root) CMD (periodic daily) ... to confirm the daily periodic cron job is being run. Also, if /Users/ronaldcross/Desktop/repairpermission.txt doesn't exist beforehand but is created after 3:15 then you know the script has run. One issue is you're trying to redirect output that's already being redirected to /var/log/daily.local by period so check that file for output. If you use the example in my last post (minus the chmod for sendmail, if you're running 10.3+) it'll work fine, with output in /var/log/daily.local. Once you've confirmed that works you could try redirecting to another file but periodic will still be using /var/log/daily.local unless you change its configuration, too. I think it's easier just using the one logfile, especially since it's system-related stuff anyway. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
|
|
#17 |
|
MVP
Join Date: Jan 2004
Posts: 1,764
|
Computer must be awake to work
I changed the system crontab to a time when the computer is awake and it works like a charm. I see output on my desktop and in the /var/log/daily.out file. I will perform this once a week as recommended by others. In the daily.out file there is a log that reads, "Running daily.local:" which is straight from the echo command of the shell script located in /etc/periodic/daily/500.daily.
The moral of the story is that the system must be awake!!! I am somewhat disappointed because I thought Apple fixed this in the 10.3.4 update. In their own words at http://docs.info.apple.com/article.html?artnum=25764 they write, "Addresses an issue in which scheduled items, such as automated backups or Software Update checks, may not work if the computer is asleep at the scheduled time. With this update, the schedule will run once the computer wakes from sleep." It now appears that this doesn't apply to cron task. I will change my system time to when the computer is most likely to be awake so that I can run this on a weekly basis. thx RLC |
|
|
|
|
|
#18 |
|
Prospect
Join Date: Jan 2002
Location: Eugene
Posts: 25
|
Glad you resolved it.
Seems cron is one of the legacy UNIX components of OS X that Apple isn't particularly interested in "modernizing", tho' according to the Tiger Preview - UNIX page the next release "enables many common UNIX utilities to handle HFS+ resource forks" so maybe there's still hope they'll finally give cron attention, too. |
|
|
|
|
|
#19 |
|
MVP
Join Date: Jan 2004
Posts: 1,764
|
Thanks for the help and the suggestions
Thanks sjk for the help and the suggestions.
If they introduce Tiger with a Cron that wakes up the computer to do an automated task, then I will purchase it hands down since that is what computing is all about, AUTOMATION. Otherwise, I am really content with Panther. thx RLC |
|
|
|
|
|
#20 |
|
Moderator
Join Date: Jan 2002
Posts: 10,677
|
FYI, daily reparing of permissions is not needed. The only times you need to repair permissions is after an install that requires an admin password, or if you've messed with the permissions in a non-user directory.
|
|
|
|
![]() |
|
|