preface
For some system and project dependence, I have the habit of following up;
MacOS has launchctl built into it to write scheduled tasks.
I chose crontab, a common Linux option.
Problems and solutions
The problem
The problem may be a system security policy problem. I tried for a long time at first;
Whether a user is permitted by root or by itself, it will say Operation not permitted.
At first, I didn’t think it was because the system version was too new (security policy), so I had no choice but to ask my colleagues to check and eliminate the grammar or some other problems.
Still have a problem, I say don’t want to go to your computer to try, his is 10.13(can run normally).
The solution
To add hard drive access, add your terminal right here
The posture of crontab
Crontab is very simple to use
-e
: Enter edit-u
: Specified user-l
: Lists the scheduling list-r
: Deletes a scheduling task
The crontab control is enabled based on the current user
Syntax format: minute hour day month week Command shell_file
# demo
*/5 * * * * /bin/zsh /Users/linqunhe/Code/u-logs/autoShell.sh
# / is every other, also supports, - this kind of specified and continuous.. See the corresponding manual for details
Copy the code
Remember to set the script permissions, such as you specify ordinary users,744 will be enough
r:4 , w:2 ,x : 1 ; U-g-o (self/group/other) -rwxr--r-- @1 Linqunhe staff 867B Dec 7 14:50 autoshell.shCopy the code
My scheduling requirements are simple, just update something that involves alias and uses ZSH (because it’s written in.zshrc)
#! /bin/zsh
source ~linqunhe/.zshrc
logPath="/Users/linqunhe/Code/u-logs/logs/$(date +'%Y-%m-%d').log"
echo '-------- update script starts walking --------------' >> $logPath
Update the NG project
cd /Users/linqunhe/Code/ng-sx-pc
ng update --all 2>&1 >> $logPath
echo '---------Ng Update End-------------' >> $logPath
# Update nuXT project
cd /Users/linqunhe/Code/nuxt2-sx-mobile-share
yarn outdated 2>&1 >> $logPath
yu
echo '---------Nuxt Update End-------------' >> $logPath
# Update umi project (Yu is my alias)
cd /Users/linqunhe/Code/umi_dva_sx_admin
yarn outdated 2>&1 >> $logPath
yu
echo '---------Umi Update End-------------' >> $logPath
# Update old react-sx-admin
cd /Users/linqunhe/Code/react-sx-admin
yarn outdated 2>&1 >> $logPath
yu
echo '---------react-sx-admin Update End-------------' >> $logPath
Update the global YARN npmyarn
ygu 2>&1 >> $logPath
echo '---------yarn global Update End-------------' >> $logPath
List global NPM packages
ygl 2>&1 >> $logPath
echo '---------yarn global list End-------------' >> $logPath
Update brew && Brew Cask
brew prune
brew update 2>1 >> $logPath
brew upgrade 2>&1 >> $logPath
brew cask upgrade 2>&1 >> $logPath
echo '----------Brew && Brew Cask Update End------------' >> $logPath
Update the MAC system
softwareupdate -i -a2 > &1 > >$logPath
echo '--------Mac OS Update End--------------' >> $logPath
echo '-------- Update script end --------------' >> $logPathIt's 1, so">/dev/null"Is equivalent to"1>/dev/null"
# 2: indicates stderr standard error
2>&1 means that the output redirection of 2 is equal to 1
Copy the code
So that’s the output
- 2018-12-07.log
conclusion
Why write task scheduling in this notebook, because notebook does not shut down all the year round.. Basically are standby state, open the cover to use..
If there is something wrong, please leave a message and we will correct it in time. Thank you for reading