Copy a file every 60 seconds bash

bash, cp, linux, loops

Solution

To answer the general question, two ways to do this, put it in a while/sleep loop or use a crontab

1) while/sleep

#!/bin/bash
while true; do
  cp -f /customTemplates/login.tpl /www/img/templates/adm/login.tpl
  sleep 60
done

2) crontab (preferred)

Run `crontab -e` and put the following line there

* * * * * cp -f /customTemplates/login.tpl /www/img/templates/adm/login.tpl

This will run the command every minute of every hour of every day of every month of every day of the week. (ergo every 60 seconds)

But, as Aaron Digulla said it would be better to get to where it's pulling the config from and edit it there, rather then overwriting it every 60 seconds.

Problem

I have a thecus nas server, and they seem to do some tricky things to their templates to display their files, currently at boot I'm running a shell command to copy one file over another, so that It boots with my custom template, however after a certain amount of time (I'm not sure what this time is) it overwrites it again with the original and my custom template is gone. Here is my current boot script: ``` #!/bin/bash cp /customTemplates/login.tpl /www/img/templates/adm/login.tpl ``` Is there a way, to perform that copy command, say every 60 seconds? the login.tpl file is only 2kb, so I wouldn't think this could cause any problems. Is there anything wrong with doing this, this way? Or is there another trick I could use?

Original source

Related problems