MacOS - Cron of MacOS Timer makes auto memory free commands possible | Apple iOS Xcode YouTube Seminar #31


macOS Catalina 10.15


- Introduction of display apps which consume cache memory
- Purge command to clear cache
- Automated command with macOS cron



* Here is the highlight of YouTube tutorial.

iOS movie apps or the development of them consume a lot of chache memory on PC without knowing. How do you solve your pc working slowly? Restart the app or pc itself?

It will waste your time and make your work inefficient. In that case, I would recommend the following code.


sudo purge



You can also confirm the remaining memory with the following command.


vm_stat | grep free
Pages free: 137884.



In my case, I often use sub display with the following apps so I was always concerned about the remaining memory.


Sidecar
Duet
Yam Display



Wireless display consumes the memory of cache so much. For example, Yam Display sometimes freeze after a long work if you don't clear the cache. I liked it because it was cheap price. But, the freeze problem annoyed me.

But, the combination of purge command and cron could solve it.

Let's edit crontab.


crontab -e

* * * * * echo 'sec' > ~/Desktop/Cron/a.txt;



At the head of command, you can see 5 asterisks. They are the positions of time settings to execute the command.


5 asterisks *
FIrst: minute
Second: hour
Third: day
Forth: month
Fifth: day of week



If you change asterisks to number, the designated timer works and execute it at the timing. The default 5 asterisks is meaning every 1 minute. So, if you would like to conduct it in a few seconds, sleep command is useful.


* * * * * sleep 10; echo '10 sec' > ~/Desktop/Cron/10.txt;
* * * * * sleep 20; echo '20 sec' > ~/Desktop/Cron/20.txt;
* * * * * sleep 30; echo '30 sec' > ~/Desktop/Cron/30.txt;
* * * * * sleep 40; echo '40 sec' > ~/Desktop/Cron/40.txt;
* * * * * sleep 50; echo '50 sec' > ~/Desktop/Cron/50.txt;



It will make txt files with the designated names per 10 seconds.

Finally, please be careful about the system mail. Whenever cron works, your system receive some mail such as error report. This may accumulate unnecessary data. So, the following command can save your storage.


mail
>/dev/null 2>&1



Let me show you how it works on YouTube seminar.


To get the source code, check the comment of my YouTube

Back to Table List

2020年04月05日