I'm seeing some strange behavior with a script getting executed by cron and I'm not really sure what's happening. The script just looks like it is going to remove the package but then just hangs at the end and never does anything.
Here's the cronjob.
06 15 * * * root /myscript.sh > /tmp/script.log 2&>1
Here's (a simplified version of) the script.
#!/bin/bash
PACKAGES_TO_PURGE="htop"
if [ -n "$PACKAGES_TO_PURGE" ]; then
echo "Purging $PACKAGES_TO_PURGE"
echo
#sudo apt-get purge -y $PACKAGES_TO_PURGE
apt-get purge -y $PACKAGES_TO_PURGE
echo "Done"
echo
else
echo "Nothing to purge"
fi
Here's the output of the log file.
0 upgraded, 0 newly installed, 1 to remove and 62 not upgraded.
After this operation, 188 kB disk space will be freed.
Done
Running this script by hand works, I only run into issues running it with cron so I'm not exactly sure what the deal is.
I can even get this script to work if I add a sudo
into the apt-get command.
I'm thinking there is something easy I'm overlooking but nothing is jumping out at me.