run script with booting process

hi all,

I write a shell script which search file in particular folder and copy another folder.after that i compare two folder if file did not match then copy file from one to another folder.Both New and New1 folder contains file with different name.
The code of my script is here

#!/bin/bash



find /home/New -name "mcm*" -exec cp -i {} /root/test/config/. \;

find /home/New1 -name "mcm*" -exec cp -i {} /root/test/updates/. \;


FROMDIR=/root/test/config/
TODIR=/root/test/updates/
cd ${FROMDIR}
for i in `find . -type f`
do
if [ ! -f ${TODIR}/$i ]
then

find /root/test/updates -mtime -1 -type f -exec rm -rf {} \;
cp $i ${TODIR}/$i
fi
done

this code is working.But i have a problem how to run this script when every time of system boot up.As soon as system boot up the files are copies in the corresponding folder using this script.If there is any modification in one file name than send file from config folder to update folder and delete the last modified file.

please help me how to run script with boot up and where i put my script (/etc/rc.d/init.d/script-name).

You appear to be on the right lines by putting your script in /etc/rc.d/init.d/script-name however these are not usually executed directly. More often there is a directory for the run-level you will be at (find the default run level record in /etc/inittab, normally the first line) For instance, if the default run level is 2, you will find /etc/rc2.d or /etc/rc.d/rc2.d or some variant depending on your operating system. Within there, you would need to create a link to your script in /etc/rc.d/init.d/script-name that starts with a capital S and two digits.

At boot time, the directory is read and the processes runs each script starting with a capital S in numerical order. It fires it off in Bourne shell by default (I think) but you can force your favourite shell as you have in your first line.

We have a few certain scripts in out rc2.d directory with names such as S96oracle to start the databases, S99quotes to start up our quotations services etc. These scripts are call with a parameter of start. This allows you to write one start/stop script and get it to reference $1. The stop script would need to be in rc2.d as K55oracle (or whatever) which is then called with a parameter stop

It depends on your operating system as to whether the K* scripts are run in numerical or reverse order. They are called when changing away from a particular run level, which is normally system shutdown time.

I hope that this helps, but please ask again if I have confused things.

Robin
Liverpool/Blackburn
UK

thanx for reply me.But i am not getting this line"you would need to create a link to your script in /etc/rc.d/init.d/script-name that starts with a capital S and two digits."I don't know how to create a link to script.

I searched S96oracle and S99quotes and K55oraclebut i did not get . got s99local.I do not know how to write start and stop script.

If you don't have anything to do at shutdown (or other change in run level) then don't bother with writing anything to recognise the start/stop parameter. The S99quotes / S96oracle are just examples of what we have, so I would not expect you to find them, so don't worry. :slight_smile:

Assuming you are in /etc/rc2.d or /etc/rc.d/rc2.d or whatever you found, issue something like:

ln -s S99script-name /etc/rc.d/init.d/script-name

This should mean that it will be picked up next boot. With S99..... it will be run very near the end of the boot, which is usually okay, but feel free to lower the number if that is appropriate, but be aware that services you may rely on (e.g. mouting filesystems, starting TCP/IP etc.) may not have been started if you set it as S01script-name.

Does that help?

Robin

hi..i want to know where i should write this code..

ln -s S99script-name /etc/rc.d/init.d/script-name

should i write this code in my shell script and save the script name as S99script1.sh..and after that put this script in etc/rc2.d..and when i boot system this script automatically copy file in respective folder...then this script is working or not?...