[linux|shell] Create a scheduled task for the written script

Script description

freeCacheTo write the shellscript and store it in the /usr/local/bindirectory, this article uses the freeCachescript example to create a freeCachescheduled task that executes the script every 10 minutes .

Set up freeCachescheduled tasks

_set_freeCache(){
    
    
    echo "*/10 * * * * root /usr/local/bin/freeCache" >> /var/spool/cron/root
}

Delete freeCachescheduled task

_del_freeCache(){
    
    
    sed "/freeCache/d" /var/spool/cron/root > /tmp/root.tmp
    mv -f /tmp/root.tmp /var/spool/cron/root
}

Other related commands

  1. View crontab log
tail -f /var/log/cron
  1. View the created tasks
crontab -l

Guess you like

Origin blog.csdn.net/macaiyun0629/article/details/108414841