I'm trying to accomplish a simple task and getting stuck. I've written a very simple script
#!/bin/bash
cd /Users/nathan/Downloads/
mv test test2
mkdir test
This works when I manually invoke it. But when trying to schedule it via launchd I'm getting 'mv operation not permitted' in the stdout.log. Can anyone advise? Thanks!
Yes, the cd was working fine.
Yes, launchd...is a pain some times. I've grown a little more familiar with it but...a 'little' lol.
Here's the script
#!/bin/bash
cd /Users/nathan/Kometa/config
# Define your Discord webhook URL
DISCORD_WEBHOOK_URL="webhook"
# Optional: You can customize the username and avatar for the webhook
USERNAME="Bash Bot"
AVATAR_URL="https://example.com/avatar.png" # Replace with an actual image URL
#Define the directory name with spaces
directory_name="28 Days-Weeks Later"
# Define the path to your directories
base_path="/Users/nathan/Kometa/config"
assets2_path="$base_path/assets2"
assets_path="$base_path/assets"
# cd /Users/nathan/Kometa/config
# DIR="/Users/nathan/Kometa/config/assets2"
# Check if the directory exists
if [ -d "$assets2_path" ]; then
# Directory exists, remove it
rm -r "$assets2_path"
# Define the message you want to send to Discord
MESSAGE="@everyone Assets2 Was Removed for the Upcoming Operation"
# Send the message using curl
curl -X POST "$DISCORD_WEBHOOK_URL" \
-H "Content-Type: application/json" \
-d "{\"username\": \"$USERNAME\", \"avatar_url\": \"$AVATAR_URL\", \"content\": \"$MESSAGE\"}"
#older assets2 removed proceed
# Rename assets to assets2 and create a new assets directory
mv "$assets_path" "$assets2_path"
mkdir "$assets_path"
# Check if 28 days-weeks later directory exists in assets2
if [ -d "$assets2_path/$directory_name" ]; then
cp -r "$assets2_path/$directory_name" "$assets_path"
else
echo "Loaned Directory $directory_name does not exist."
fi
# Send a success message using Discord webhook
MESSAGE="@everyone Kometa Assets Were Successfully Pruned"
# Send the message using curl
curl -X POST "$DISCORD_WEBHOOK_URL" \
-H "Content-Type: application/json" \
-d "{\"username\": \"$USERNAME\", \"avatar_url\": \"$AVATAR_URL\", \"content\": \"$MESSAGE\"}"
else
# Directory doesn't exist proceed with mv
# Rename assets to assets2 and create a new assets directory
mv "$assets_path" "$assets2_path"
mkdir "$assets_path"
# Check if 28 days-weeks later directory exists in assets2
if [ -d "$assets2_path/$directory_name" ]; then
cp -r "$assets2_path/$directory_name" "$assets_path"
else
echo "Loaned Directory $directory_name does not exist."
fi
# Send a success message using Discord webhook
MESSAGE="@everyone Kometa Assets Were Successfully Pruned"
# Send the message using curl
curl -X POST "$DISCORD_WEBHOOK_URL" \
-H "Content-Type: application/json" \
-d "{\"username\": \"$USERNAME\", \"avatar_url\": \"$AVATAR_URL\", \"content\": \"$MESSAGE\"}"
fi
And here's the launchd agent
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.nathan.assetpurge</string>
<key>ProgramArguments</key>
<array>
<string>/Users/nathan/daps_other/myscripts/other/assetpurge.sh</string>
</array>
<key>RunAtLoad</key>
<false/>
<key>StartCalendarInterval</key>
<array>
<dict>
<key>Day</key>
<integer>1</integer>
<key>Hour</key>
<integer>1</integer>
<key>Minute</key>
<integer>00</integer>
</dict>
</array>
<key>StandardErrorPath</key>
<string>/tmp/stdout.log</string>
<key>StandardOutPath</key>
<string>/tmp/stderr.log</string>
</dict>
</plist>
Thanks for reading!
cdcommand successful?launchdservice, when executinglaunchdjobs, has to be granted permission to make changes in the user’s home directory, or something.