Question

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?

Was it helpful?

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.

OTHER TIPS

A better solution would be to find out where the NAS takes the original file from.

Execute this command to find possible candidates:

find / -name "login.tpl"

You can also use patterns: "*login*"

I suggest to use the quotes when you use patterns, otherwise it might match files in the local folder and the shell will then replace the name before it passes the argument to find.

To find out who changes the file, use auditctl (see this question).

try the following solution:

chmod +x /tmp/test.sh

your script test.sh:

#!/bin/bash
cp -f /customTemplates/login.tpl /www/img/templates/adm/login.tpl

then do:

touch /tmp/cronjob
echo "* * * * * ./test.sh" > /tmp/cronjob
/etc/init.d/crond/start
crontab /tmp/cronjob

If you're looking for a throw-away, one time sort of solution, you can use the watch utility

watch -n 60 ./test.sh

runs ./test.sh every 60 seconds and echoes the output to stdout

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top