How to Run a Shell Script Every Day on a Mac

Power Manager can be used to automatically run a shell script each day. Shell scripts can be used to perform tasks that are difficult, or impossible, to achieve using the graphical Mac OS X interface.

Let's walk through how to schedule a shell script to run once a day. Our shell script will mount a shared disk hosted on a Windows computer.

Create a Scheduled Shell Script

  1. Launch System Preferences and select Power Manager.
  2. Click Add… to create a new event.
    Select Add to begin creating a new Power Manager event.
  3. Choose the template Run a script daily.
    Select Run a script daily in the Power Manager Schedule Assistant.
  4. Click Continue to the Script step.
  5. Copy and paste your shell script into the Script step.
    #!/bin/sh
    
    mount_smbfs //dssw@winserver.local/share /Volumes/share

    The shell script can be run as the root user, as a normal user, or even as whoever is currently logged in at the time. For this script, we have set the Environment to Super User (root).

    Copy and paste your shell script into Script.
  6. Click Continue to the When step.
  7. Adjust the time and days to read 9:00, with Monday through Sunday selected.
    Adjust the time and days of your Power Manager event.
  8. Continue through the remaining steps until your event is created.

With these steps completed, your shell script is now ready. Power Manager will perform the event and run your script once each day at 9:00.

Your shell script is ready to be performed by Power Manager.

If needed, Power Manager will automatically wake up your Mac in order to perform your daily shell script.

This article was posted in , , and and tagged , , and .

Published by Graham Miln on