run script with booting process


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting run script with booting process
# 1  
Old 12-03-2010
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
Code:
#!/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).

Last edited by Franklin52; 12-03-2010 at 09:23 AM.. Reason: Please use code tags
# 2  
Old 12-03-2010
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
# 3  
Old 12-03-2010
Quote:
Originally Posted by rbatte1
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.
# 4  
Old 12-03-2010
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. Smilie

Assuming you are in /etc/rc2.d or /etc/rc.d/rc2.d or whatever you found, issue something like:
Code:
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
# 5  
Old 12-03-2010
Quote:
Originally Posted by rbatte1
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. Smilie

Assuming you are in /etc/rc2.d or /etc/rc.d/rc2.d or whatever you found, issue something like:
Code:
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..
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?...
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Red Hat

How to run a process through shell script.?

hey , i have to write a script to run a process through shell script and if the process runs successfully then return success. i used nohup to start the process but nothing occured . #!/bin/sh nohup ./cvt -f MediationSources.xml & can anyone pls help me Thanks (3 Replies)
Discussion started by: ramsavi
3 Replies

2. Shell Programming and Scripting

run this script as a daemon process

Hi, HI , I have a simple script that moves files from one folder to another folder, I have already done the open-ssh server settings and the script is working fine and is able to transfer the files from one folder to another but right now I myself execute this script by using my creditianls to... (3 Replies)
Discussion started by: nks342
3 Replies

3. Shell Programming and Scripting

How to run a particular process

Hi I have a perl script where i created 3 nmap scans and the results will output to a text file. But when i run the code the first ip address gets scanned then the others after, but i want to be able to choose which ip address to scan. Here is my code: (`nmap -v -r 99.xxx.xxx -p... (0 Replies)
Discussion started by: kingbp
0 Replies

4. Shell Programming and Scripting

script to monitor the process system when a process from user takes longer than 15 min run.

get email notification from from system when a process from XXXX user takes longer than 15 min run.Let me know the time estimation for the same. hi ,any one please tell me , how to write a script to get email notification from system when a process from as mentioned above a xxxx user takes... (1 Reply)
Discussion started by: kirankrishna3
1 Replies

5. Shell Programming and Scripting

Help with shell script to run a converter process

Hi, I have about 500 binary files. I have a command to convert these files to text. The command usage is: converter bin-file txt-file I have to input the name of the binary file and the name of the text file. I'm thinking something like this will work, but not really sure: for file in... (1 Reply)
Discussion started by: bbbngowc
1 Replies

6. Shell Programming and Scripting

Startup Script "run process with Timer"

Hi I have a script that execute every X minute for checking new files in a folder and converting to pdf. Is there any way to start this script automatically on linux startup?. I use sleep function in script with infinite loop. while do killall -u `whoami` -q soffice soffice... (0 Replies)
Discussion started by: zawmn83
0 Replies

7. UNIX for Dummies Questions & Answers

How can I run a process under particular ID?

I have a script that needs to run under ID say "xyz". the way I do normally is to "su" to the id, enter the password of "xyz" and run the process. However, is there any way run the process under "xyz" without "su" to the ID. A person with root access would be able to run any process under any ID as... (4 Replies)
Discussion started by: ucbus
4 Replies

8. Shell Programming and Scripting

Perl: Run perl script in the current process

I have a question regarding running perl in the current process. I shall demonstrate with an example. Look at this. sh-2.05b$ pwd /tmp sh-2.05b$ cat test.sh #! /bin/sh cd /etc sh-2.05b$ ./test.sh sh-2.05b$ pwd /tmp sh-2.05b$ . ./test.sh sh-2.05b$ pwd /etc sh-2.05b$ So... (10 Replies)
Discussion started by: vino
10 Replies
Login or Register to Ask a Question