[x] Welcome to LinuxSolved.com Linux help forums, here we are a community of Linux users helping each other. It is helpful to both ie. new linux users as well experienced one. We always have our experts to help you and ofcourse members help each other, so you can ask for help any time by Registering.: Click to Register

Welcome, Guest. Please login or register.
Did you miss your activation email?


Login with username, password and session length

Linux Forums - Linux Help,Advice & support community:LinuxSolved.com  |  Forum  |  Linux in General  |  Linux Development & Programming  |  Topic: How to run a shell script using service command
The LinuxSolved.com GNU/Linux User Communit - Forum
Welcome to LinuxCommunity You have just arrived to a friendly linux community which is helping Linux Users from Years.. You can be its part if you have not already joined it. Registration is FREE and is gateway to unlimited help and support to all your linux related needs. If you are an GNU/Linux supporter then you have come to the right place.
Pages: [1]
  Print  
Author Topic: How to run a shell script using service command  (Read 1812 times)
0 Members and 1 Guest are viewing this topic.
sridip
Linux Noob !
*
Offline Offline

Posts: 9


View Profile
« on: August 10, 2005, 06:07:05 AM »

I want to run a shell script using service command
as service <script> start
    service <script> stop
how can i do this ?
Logged
misterscorp
New Member

Offline Offline

Posts: 3


View Profile
« Reply #1 on: October 07, 2005, 12:45:10 PM »

Hi,
  Just write the script to do your specific function & put the shell file in the /etc/rc.d/ directory
  Before writing the script file just get a glance of how the other service deamons are written. For example if you have webmin(Administration tool) installed in your linux box you can go and find its script in /etc/rc.d/rc5.d/
the name of the file would be S99webmin
plz do read that file. You will get the idea how they are invoking a deamon using service command. Actually they will be having a seperate file that can handle the start|stop|restart and how these functionalities are acheived can be better undestood if you read that script file.


I think this would have satisfied your questions,
 Cheesy Cheesy  Cool
Logged
dragoncity99
LST CareTaker
Experienced
*****
Offline Offline

Posts: 494


View Profile
« Reply #2 on: May 07, 2006, 09:13:36 AM »

Ok make sure u know what u r doing sridip.

U must make sure ur Linux distro is either using

System V or BSD style of managing runlevel.

System V is normally used, coz it's cool way of handling runlevels.

BSD which is used by Slackware is different.


I suggest u do a reading first on this topic. If ur using distros such as RedHat/SUSE which uses System V,

U need to add ur script into /etc/rc.d/init.d directory.

/etc/rc0.d
/etc/rc1.d
/etc/rc2.d
/etc/rc3.d
/etc/rc4.d
/etc/rc5.d
are all symbolics to that script in /etc/rc.d/init.d

u don't have to manually create it. There are tools that help u to do it, if ur using Redhat
Logged
dragoncity99
LST CareTaker
Experienced
*****
Offline Offline

Posts: 494


View Profile
« Reply #3 on: May 07, 2006, 09:17:10 AM »

Sorry for reposting, but if u want to just get things done and not challenging urself or being curious, a QUICK FIX, will be:

1. Run the script in background
# ./yourShellScript.sh &

2. That's it. If you wanna stop it, u can just find the PID, using:
# ps aux | grep yourShellScript.sh

3. Kill the pid:
# kill -9 PID-OF-YOUR-SHELL-SCRIPT
Logged
Linux Forums - Linux Help,Advice & support community:LinuxSolved.com
   

 Logged
Pages: [1]
  Print  
 
Jump to:  

Related Topics
Subject Started by Replies Views Last post
BASH SHELL SCRIPT Linux Development & Programming nicksthegreat 1 1321 Last post April 08, 2004, 06:02:04 AM
by sudipta_cht
Running shell Script Linux Development & Programming shipoin_97 1 947 Last post December 14, 2005, 08:56:18 AM
by dragoncity99
run shell script immediatly u do # rpm -ivh Linux Development & Programming ganeshgore81 2 1054 Last post September 18, 2007, 07:01:41 AM
by gauravbajaj
shell script and binary together Linux Development & Programming ganeshgore81 1 865 Last post January 23, 2006, 12:03:42 PM
by dragoncity99
Shell Script Miscellaneous gauravbajaj 6 863 Last post May 08, 2006, 05:34:32 AM
by gauravbajaj
Welcome, Guest. Please login or register.
Did you miss your activation email?
November 22, 2008, 10:00:54 AM

Login with username, password and session length
Navigation
Recent Discussions
[November 20, 2008, 11:30:52 PM]

[November 19, 2008, 07:52:41 PM]

[November 19, 2008, 07:52:36 PM]

[November 17, 2008, 10:42:59 AM]

[November 16, 2008, 12:49:47 AM]

[November 16, 2008, 12:48:58 AM]

[November 15, 2008, 08:29:02 AM]

[November 15, 2008, 08:24:41 AM]

[November 14, 2008, 05:11:50 AM]

[November 13, 2008, 03:28:22 AM]
Members
Total Members: 6227
Latest: karunadct
Stats
Total Posts: 8269
Total Topics: 2253
Online Today: 10
Online Ever: 111
(June 28, 2007, 06:47:29 AM)
Users Online
Users: 0
Guests: 10
Total: 10
Privacy Policy| Powered by SMF 1.1.4 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks
Theme & TinyPortal v0.9.8 © Bloc