Using cron job to move files from dreambox to nas
A few weeks ago my IDE 180GB harddisk of my dreambox 7020 was nearly 90% full. Bying a new IDE drive is almost as expensive as bying a 3TB NAS. Besides I already have a NAS so why not use it for the dreambox?
The easiest way to move the files from the dreambox to the NAS would be to get the drive out, put it my desktop and move all files to the NAS. Another option would be to start a SSH connection and from there move all the files to the NAS. The disadvantage of that would be that my computer needed an SSH connection for more than 12 hours. So I started wondering whether I could fix this problem with a simple cronjob.
First you need to mount your NAS. My /etc/fstab look like this:
rootfs / auto defaults 1 1
//xxx.xxx.xxx.xxx/[FOLDER_ON_NAS] /media/nas/DreamBox cifs username=[USERNAME],password=[PASSWORD],uid=1000 0 0
If you need help with mounting a NAS on a dreambox. Take a look at my previous blog:
Mounting a Buffalo Linkstation NAS
Next steps need to be performed as root. Create the following folders if they don't exist:
#if crontabs dir does not exist:
#if tmp dir does not exist:
After having the right directories, I created a file '/home/root/movemedia.sh' with the following content:
mv /media/usb/movie/* /media/nas/DreamBox/movie/. 1>/home/root/tmp/movie.txt 2>&1
mv /media/usb/audio/* /media/nas/DreamBox/audio/. 1>/home/root/tmp/audio.txt 2>&1
The 'touch' commands are purely to see at which step we are. The log files are for errors if anything goes wrong. After creating the file, you need to set the access flags.
chmod 755 /home/root/movemedia.sh
First check that you have the right folders on the NAS and the correct access rights:
Check that the files exist:
ls -l /media/nas/DreamBox/movie/1
ls -l /media/nas/DreamBox/audio/2
Remove the test files:
So now we have:
the right folders and rights on the NAS a script that moves the files
Now we get at the crontab part. The crontab has a lot op schedule possibilities. I just want my script to run once so I set it to run at a certain time, once a year. After the crontab is ready with its job, I will remove the job. Use the following command to edit the crontab:
An editor session is started. If the window is empty, add the following:
# Minute Hour Day of Month Month Day of Week Command
# (0-59) (0-23) (1-31) (1-12 or Jan-Dec) (0-6 or Sun-Sat)
51 20 7 1 * /home/root/movemedia.sh
As you can see, my cron job will start at January the 7th at 20:51 and it will run the following command:
You can check your crontab with the following command:
It shows the content of the crontab. It should show you the text you just entered.
When I edited my crontab, I set it to a time and date 1 minute from 'then'. So I didn't have to wait too long. After a minute, I saw my step1 file, so I new the process was running. Now I could close my ssh session. The cron job keeps running. After more than 12 hours, I saw that all the files where moved to the right place.
The next steps I did
change the video and audio locations in the dreambox recording menu unmount the hard disk disabled the 12 V output in the menu Restarted the dreambox
And 'Et voilà' my dreambox now records and plays back to and from the NAS.