'Trying to make a cron job to move my files from desktop to a temp file at the end of the day

I want to make a simple cron job that moves all the files on my desktop to a temp folder at the end of the day. for debugging I wrote this bash script that works when I run it using bash:

#!/bin/bash
/bin/mv ~/Desktop/* ~/Temp

saved the script and I am using the following cron job:

59 23 * * * /bin/mv /Users/username/Desktop/* /Users/username/Temp

The cron job executes when I tested printing something to a file. but somehow it will not move files? Is there something I am missing?



Solution 1:[1]

Suggesting to fix your bash script with correct user context.

Since ~ is defined by user's context.

It is possible to replace each ~ with $HOME path:

 sed -i "s|~|$HOME|g" your-script.sh

And/Or include users context in your script:

 sed -i "2i source $HOME/.bash_profile" your-script.sh

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dudi Boy