OK you need a couple of things.
First create a script to do what you want using your favorite editor in the directory you want the script to exist (e.g. vi /usr/local/bin/fix_config.sh)
Code:
#!/bin/bash
# fix_cocnfig.sh
#
PATH=$PATH:/bin:/usr/bin
if grep -q abcdefghijklmnopqrstuvwxyz config.cf
then echo config.cf is OK
else cp /var/www/test/config.cf config.cf
fi
Next create a cron entry to run the script with the "crontab -e" command which puts you in a vi session of cron.
In the vi session of cron enter a line like:
Code:
00,10,20,30,40,50 * * * * /usr/local/bin/fix_config.sh >>/var/log/fix_config.log 2>&1
DISCUSSION:
In the above script the first line is called the interpreter line when it starts with "#!". This tells it what shell or program to run the rest of the commands as. I'm assuming you're doing this on Linux. If not you may need to pick another shell (e.g. ksh or posix sh on UNIX).
The PATH is a variable that tells it where to look for executable commands. Typically when logged in your PATH is already set but cron and some other background jobs get minimal settings so you want to insure PATH contains the directories that use the commands you want. You can determine those by running "which <command>" for the commands you're going to use (e.g. "which cp" and "which grep")
The "if", "then", "else", "fi" seen in next three lines is a standard conditional. (elif is also available). It evaluates the condition and if true it does the "then" and if not does the "else".)
The "grep -q abcdefghijklmnopqrstuvwxyz config.cf" uses the grep command which searches for patterns. The -q option tells it not to give any output but just test whether the pattern you look for is there. This is what the "if" is testing for - if it finds the
pattern it just outputs a note saying it is OK. If not it does the copy using the cp command. The "fi" tells it to end the conditional as you can have quite a bit more than one line for the "then", "else" and "elif" steps in more complicated scripts.
Note that the cp has the full path for the source file but not for the target because you didn't tell us where the target lives. You probably want to put in a full path for the target.
The cron entry is an example. The first few fields are the time specification for when it should run:
00,10,20,30,40,50 * * * *
The first section specifies it should run every 10 minutes. The fields with "*" mean it should run every day every hour. You'd have to adjust all these fields to run it when you want.
The "/usr/local/bin/fix_config.sh >>/var/log/fix_config.log 2>&1" is the actual command line that will be run each time. It is running your new script and appending its output to a log called /var/log/fix_config.log. It is also sending any errors to that same log by redirecting standard error (stderr, file descriptor 2) to standard output (stdout, file descriptor 1). Note that you don't have to log at all so you could leave out the ">>/var/log/fix_config.log 2>&1". If you DO log make sure you keep track of the size of the log to avoid filling up your /var.
I'd suggest you do a Google search for "shell scripting tutorial" to get the basics of scripting.
You can also use the built in manual system to get details of most commands by simply typing "man <command>" as for example:
man grep
man cp
man cron
man crontab
man bash
man echo