Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

A simple shell script to run system maintenance tasks UNIX
I created this simple bash script to perform periodic maintenance. I put the script file in my ~/bin directory, and I added the folliwing line to my .profile file (where my_user is my short username):
  export PATH=$PATH:/Users/my_user/bin
Now, when I want to perform maintenance, I open a Terminal window and type maint at the prompt.

[robg adds: Remember to chmod 655 ~/bin/maint to make the code executable. We've had a number of hints here over the years dealing with the periodic maintenance scripts. There are also numerous utility apps that will do this for you as well.]
    •    
  • Currently 1.50 / 5
  You rated: 2 / 5 (4 votes cast)
 
[18,340 views]  

A simple shell script to run system maintenance tasks | 14 comments | Create New Account
Click here to return to the 'A simple shell script to run system maintenance tasks' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A simple bash script to run system maintenance tasks
Authored by: goatbar on Dec 20, '06 08:16:15AM

Seems that the script link is broken.



[ Reply to This | # ]
correct link
Authored by: anoved on Dec 20, '06 08:22:49AM
I believe the correct link is http://www.macosxhints.com/dlfiles/bash_maint_sh.txt (missing the "t" in "maint" in the original hint).

[ Reply to This | # ]
Correct perms...
Authored by: jwigdahl on Dec 20, '06 08:26:53AM

Perms should be 755 to make the script executable.... 655 will only set read/write for the owner and not execute.



[ Reply to This | # ]
Correct perms...
Authored by: gidds on Dec 20, '06 12:14:21PM
Yeah, but now we're in the 20th century, why do people even use numeric perms in the first place? I can never remember what the octal bits mean, whereas something like 'u=rwx,go=rx' makes it all pretty clear.

---
Andy/

[ Reply to This | # ]

Correct perms...
Authored by: mbenchoff on Dec 20, '06 01:15:10PM

Really? I've always found the numbers easier to remember myself. Read equals 4, write equals 2, and execute equals 1. A simple (for me, anyway) three-digit number seems more efficient and to the point. But then, it's always nice to have more than one way to do something.



[ Reply to This | # ]
A simple bash script to run system maintenance tasks
Authored by: ofermod on Dec 20, '06 08:39:15AM

There's no end to problems with this hint :(

In addition to the permissions being wrong, the script is written in csh, so it's not even a bash script!

(Don't get me wrong tho', I do love this site :) )



[ Reply to This | # ]
A simple bash script to run system maintenance tasks
Authored by: wallybear on Dec 20, '06 08:41:09AM
You can simply use PseudoAnacron (a donationware on www.jaw.it) that will automatically perform missed periodic tasks for you. It's a startup item.

[ Reply to This | # ]
A simple bash script to run system maintenance tasks
Authored by: rammjet on Dec 20, '06 10:12:37AM

The system normally performs these maintenance operations at about 3:00 AM if you leave your computer running. Apple used to use crontabs to spawn the maintenance operations, but now uses its own LaunchDaemons server.

If you go to the directory: /System/Library/LaunchDaemons you will find all of the different scheduled events. If you edit the following 3 files (as root - sudo), then you can change the times that the maintenance functions get performed.

In these files, edit the bottom 2 key/integer pairs to change the start time:

com.apple.periodic-daily.plist
com.apple.periodic-monthly.plist
com.apple.periodic-weekly.plist

Repair permissions after the modification.



[ Reply to This | # ]
A simple bash script to run system maintenance tasks
Authored by: TvE on Dec 20, '06 10:47:19AM

I find it a lot easier to either:

A) Leave the Mac on all times

B) type "sudo periodic daily"
then hit Arrow up and erase the last word and type weekly
then hit Arrow up and erase the last word and type monthly

It seems like scripting for the sake of scripting :-)



[ Reply to This | # ]
A simple bash script to run system maintenance tasks
Authored by: tjj on Dec 20, '06 01:21:28PM
Nothing wrong with scripting for the sake of scripting, if you're learning;) What irritates me with the launchd jobs is, that they are marred by sleeping the machine.
xxx:~ xxx$ date; ls -al /var/log/*.out; ls -alu bin/rdiff-backup.sh 
Wed Dec 20 21:15:01 CET 2006
-rw-r--r--   1 root  wheel  51797 Dec 17 13:46 /var/log/daily.out
-rw-r--r--   1 root  wheel    251 Nov  8 23:25 /var/log/monthly.out
-rw-r--r--   1 root  wheel    254 Oct 28 15:49 /var/log/weekly.out
-rwxr-xr-x   1 xxxx  xxxx  1393 Dec 19 20:30 bin/rdiff-backup.sh
The last line is a back-up script that is also run by launchd. Once in a while I do a
sudo periodic daily weekly monthly
in one go.

[ Reply to This | # ]
A simple bash script to run system maintenance tasks
Authored by: luomat on Dec 20, '06 02:55:06PM

Indeed, although all I really need to remember is:

7 = executable
6 = read/write
5 = read/execute (no write)
4 = read only
0 = access denied

1 = execute only (rare)

I've never found the letters as easy to remember as the numbers.



[ Reply to This | # ]
A simple bash script to run system maintenance tasks
Authored by: allanmarcus on Dec 20, '06 10:21:27PM

These tasks are run automatically for you. If you Mac is off atthe preset time, the task run as soon as you power up. This is one of the advantages of launchD over cron.



[ Reply to This | # ]
A simple shell script to run system maintenance tasks
Authored by: tjj on Dec 21, '06 04:02:55PM
Well, the trouble is, as alluded to above, that the task are not run when the computer is awoken from sleep. This has been an issue for quite a while now, and has been discussed in several threads here if my memory doesn't trick me. [link:]http://forums.macosxhints.com/showthread.php?t=39005&highlight=periodic+sleep[/link:] Damn!, Can't make that link work, sorry.

[ Reply to This | # ]
A simple shell script to run system maintenance tasks
Authored by: rocteur on Dec 22, '06 03:25:18AM
Beware when someone says:

I created this simple bash script

And the script starts:

#!/bin/csh

Which is clearly C shell not bash!

And this:

set choice = $<

Which is clearly C shell not bash!

And Don't forget to read this:

http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/



[ Reply to This | # ]