I need to run some scripts every night to move some files around in OMV. I want something that simple and easy to maintain and more or less stock standard.
There are probably many variations on how this could be done but this is how I chose to do it.
Before we start it is worth noting I have my RAID mounted by OMV at:
/media/f20b47a4-d207-40aa-a7e6-42ea82354455
1. | Ensure you have enabled home directories for users. I created a shared folder called “/home” and enable this in “Access Rights Management | Users | Settings”: |
2. | Create a user called “scheduledtasks” and make a member of the groups as all your other users. As a result this user should have a home directory along the lines of:
/media/f20b47a4-d207-40aa-a7e6-42ea82354455/home/scheduledtasks |
3. | Create a shared folder called “scheduled_jobs”, I would also add this as a windows/smb shared folder. |
4. | In this folder create a simple shell script:
#!/bin/sh echo "Running script /scheduled_jobs/test.sh" |
5. | Create a scheduled task with a command of:
bash ~/../../scheduled_jobs/test.sh |
6. | Once you have saved the task click on the “Run” button to show the dialog to “Execute cron job” – click on “Start”. It should return “Running script /scheduled_jobs/test.sh”, which is of course the echo command inside the script. |
When I setup a real task I found that for the types of task I wanted to do, including mounting SMB shares I needed to run it as root. This meant that I needed to specify the full path to my RAID drive. Thus my scripts started like:
#!/bin/sh
#
# Script to archive appropriate folders
# to the Archive folder.
#
# Tony Paterson
# May 2007
#
RAIDRoot="/media/f20b47a4-d207-40aa-a7e6-42ea82354455"
# Source function library.
if [ -x /etc/rc.d/init.d/functions ]; then
. /etc/rc.d/init.d/functions
fi
#
# Get the date in the format "Day of Week" and time
# This will mean that we will effectively keep a weeks backup
#
SHORTDATE=`date +%a`
#
# User config section
#
ArchiveFolder="${RAIDRoot}/backups/daily/essentials"
LogDir="${RAIDRoot}/backups/daily/logs"
LOGFILE="${LogDir}/backup_essentials.log"
#
# archive folder exists
#
echo "Creating Backup Directory..."
echo "Creating Backup Directory..." >> $LOGFILE
su - root -c "rm -Rf ${ArchiveFolder}"
su - root -c "mkdir -p -v ${ArchiveFolder} "