20 C
London
Sunday, September 1, 2024

terminal – Having interval job to take away non permanent recordsdata


I’ve outlined a periodic plist which runs a bash script. The plist is positioned within the native library and script can be place in /usr/native/bin. It efficiently run the script on the outlined interval however it errored about not having sufficient permission to run the discover command. Discover command is used within the script and working script with out plist works as anticipated.

/usr/native/bin/cleanup.sh

#!/usr/bin/env bash

stable_folders=(
    "$HOME/Downloads"
    "$HOME/Downloads/Telegram Desktop"
    "$HOME/Downloads/samba"
    "$HOME/Downloads/xandikos"
    "$HOME/Downloads/copyparty"
    "$HOME/Downloads/swagger"
    "$HOME/Downloads/motion pictures"
)

for folder in "${stable_folders[@]}"; do
    mkdir -p "$folder" || true
achieved

whereas learn -r folder; do
    # shellcheck disable=2076
    if [[ ! " ${stable_folders[*]} " =~ " ${folder} " ]]; then
        echo "eradicating $folder..."
        rm -rf "$folder"
    fi
achieved < <(discover "$HOME/Downloads" -maxdepth 1 -mtime +12h)

whereas learn -r file; do
    echo "eradicating $file..."
    # shellcheck disable=2076
    rm -rf "$file"
achieved < <(discover "$HOME/Downloads/Telegram Desktop" -mindepth 1 -mtime +15m)

~/Library/LaunchAgents/me.1995parham.cleanup.plist

<?xml model="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist model="1.0">
<dict>
  <key>Label</key>
  <string>me.1995parham.cleanup</string>
  <key>ProgramArguments</key>
  <array>
    <string>/usr/native/bin/cleanup.sh</string>
  </array>
  <key>StartInterval</key>
  <integer>60</integer>
  <key>StandardOutPath</key>
  <string>/choose/homebrew/var/log/cleanup.log</string>
  <key>StandardErrorPath</key>
  <string>/choose/homebrew/var/log/cleanup.log</string>
</dict>
</plist>

and these are the errors:

discover: /Customers/parham/Downloads: Operation not permitted
eradicating /Customers/parham/Downloads...
rm: /Customers/parham/Downloads: Operation not permitted
discover: /Customers/parham/Downloads/Telegram Desktop: Operation not permitted
discover: /Customers/parham/Downloads: Operation not permitted

Latest news
Related news

LEAVE A REPLY

Please enter your comment!
Please enter your name here