0
votes

Hello everyone i am facing issues with ram memory so every 1 hour I open the terminal on my mac os and type in purge to free up memory. I wanted to know how to write the shell script and cron it. The cron part i know already just needed help with the applescript part

Many thanks :)

3

3 Answers

0
votes

if you already know how to use cron, then simply using cron to schedule purge command.

$ purge #/usr/bin/purge

will free up memory.

2
votes

I have the same memory leak issue with my 2009 MacBook Pro, so I created a Bash script that checks to see if I have less than 100MB of free RAM, then performs a 'nice purge' if needed. Then I added a crontab to automatically run this check every 30 minutes, so I am hands-free now. From the terminal create a new file called free.sh with contents:

#!/bin/bash
free=`vm_stat | grep free | awk '{print $3}'`
freer=${free%%.*}
if [ "$freer" -lt "18000" ]
then
    nice purge
fi

Next, from the terminal run this command:

crontab -e

Enter in the following and type in your username:

*/30 * * * * /Users/your-username-goes-here/free.sh

This tells cron to run your free.sh script every 30 minutes.

-1
votes

Honestly, I wouldn't mess with your terminal for that. Open automator and set it to do that.

Open automator and run shell script. Look here: enter image description here