Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have a program that downloads some files. I want those files to automatically change permissions to 755, and get moved to another folder on my system. I want this to autorun every hour.

Is this possible? I'm not good at scripting, but I'm pretty good in terminal. My system is an Ubuntu server 12.04.

share|improve this question

1 Answer 1

up vote 4 down vote accepted

Sure you can.

The script might look something like this:

#!/bin/bash

# Set permissions
chmod 755 /home/user/Downloads/*

# Move files
mv /home/user/Downloads/* "/home/user/New Location/"

Save this as something like /home/user/download-script.sh and make sure to run chmod u+x /home/user/download-script.sh so it can be executed.

To have this executed periodically you could use cron. Enter crontab -e and create an entry like this:

0 * * * * /home/user/download-script.sh

This would lead to the script being executed every hour exactly (so, say 1:00 am, 2:00 am, etc.).

You can expand on this of course. Depending on whether there might be folders in you Downloads directory, you might want to add -R to the chmod-command to make changes recurse into those directories for example. Hope this helps :).

Note: You might want to be careful about when you use 755 as far as permissions go! Does everybody really need to execute those files? Maybe something like 764 is enough already.

share|improve this answer
    
Thank you. Exactly what I was looking for! Can I make this to run without login in? Sometimes the power goes out, and I have the people I live with starting the server again. Will this run after a boot? :) About the permissions. I took 755 like an example, I think 764 would be better. I understand all of the script, but the crontab "0 * * * * /home/user/download-script.sh" wil this make it run as my user, or root? –  Fyksen Jan 30 '13 at 15:03
2  
Yes, this will run even if you don't log in! If you run crontab -e with your regular user's account, the script will be executed as that user, too. if you do sudo crontab -e the script will execute with root's permissions. Also, if this answer solved your question, feel free to mark it as such :). –  Michael Biech Jan 30 '13 at 15:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.