Fedora Linux Support Community & Resources Center

Go Back   FedoraForum.org > Fedora 17/18 > Servers & Networking
FedoraForum Search

Forgot Password? Join Us!

Servers & Networking Discuss any Fedora server problems and Networking issues such as dhcp, IP numbers, wlan, modems, etc.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 7th July 2010, 07:44 AM
abhijitsarangi Offline
Registered User
 
Join Date: May 2010
Posts: 58
linuxfirefox
How to run a shell script as a servive/daemon

Hi all,

I have a script as report.sh which prints its out put in some file.

Now I want to run this as a service so that when I start this service it shud run in the background and give me the out put.

Again I should be able to stop it and I should able to configure its so that it can start when I start my system.


What I have done

In the /etc/services

I have added report 5555/tcp

Then in the /etc/xinetd.d I have created a file report_com where I have given

service report
{
socket_type = stream
protocol = tcp
wait = no
user = root
server = /home/openuser/Desktop/report.sh
port = 5555
}


now ehen I type /etc/init.d/xinetd restart it shows no such files or directory.


Now I dont know what to do..


Could anyone guide me Whether I have done correct or not?

If not then how can I run My scrip as a service..


Please...
Reply With Quote
  #2  
Old 7th July 2010, 07:54 AM
giulix's Avatar
giulix Offline
"Fixed" by (vague) request
 
Join Date: Oct 2005
Location: GMT+ 1
Posts: 2,950
linuxfedorafirefox
Re: How to run a shell script as a servive/daemon

xinetd is for network services. You would probably be better off with chkconfig. Have a look at the service scripts in /etc/init.d for examples. Anyway, for a report, the most appropriate solution would probably be to run it as a cron job
Reply With Quote
  #3  
Old 7th July 2010, 08:12 AM
abhijitsarangi Offline
Registered User
 
Join Date: May 2010
Posts: 58
linuxfirefox
Re: How to run a shell script as a servive/daemon

actually am a bit new to services..

could you plese tell me the commands/steps how to place the sript to make it a service.

I know about cron but cron will run the service at a perticular time and once script is finish it will stop which wont solve my problem...

Thank you in advance..
Reply With Quote
  #4  
Old 7th July 2010, 08:22 AM
giulix's Avatar
giulix Offline
"Fixed" by (vague) request
 
Join Date: Oct 2005
Location: GMT+ 1
Posts: 2,950
linuxfedorafirefox
Re: How to run a shell script as a servive/daemon

Ok, I see... have a look at chkconfig, then. Two ways to do that:
1) Open a terminal and type `man chkconfig'
2) Press F1 on the desktop, then type `chkconfig' in the Search box and press Return/Enter; click on `chkconfig manual page'

As for examples, have a look at the files contained in the /etc/init.d directory. These are all the scripts that are run by init to start/stop services when the system switches from one runlevel to another. Google these terms for a better understanding of what's going on when the system starts up/shuts down...

P.S. Anyway, that won't solve the problem about the service running once and then dying. More work is necessary in order to write a daemon service

Last edited by giulix; 7th July 2010 at 08:28 AM.
Reply With Quote
  #5  
Old 7th July 2010, 08:26 AM
abhijitsarangi Offline
Registered User
 
Join Date: May 2010
Posts: 58
linuxfirefox
Re: How to run a shell script as a servive/daemon

My script is

#!/bin/sh
w >> /home/openuser/Desktop/report.txt
Reply With Quote
  #6  
Old 7th July 2010, 08:38 AM
giulix's Avatar
giulix Offline
"Fixed" by (vague) request
 
Join Date: Oct 2005
Location: GMT+ 1
Posts: 2,950
linuxfedorafirefox
Re: How to run a shell script as a servive/daemon

May I ask how many times/how frequently does it need to be run? Has it got to be triggered by some event? Is this some kind of exercise?
Reply With Quote
  #7  
Old 7th July 2010, 08:45 AM
abhijitsarangi Offline
Registered User
 
Join Date: May 2010
Posts: 58
linuxfirefox
Re: How to run a shell script as a servive/daemon

no actually I am trying to create a service which can be run at the atarting of the system like any other service like (psacct or httpd) so that I can monitor whcich user is using which command...

---------- Post added at 01:45 PM CDT ---------- Previous post was at 01:42 PM CDT ----------

c the psacct will not solve my purpose as it is not giving the entair command like..


let say 10 users have used "rm" command then I want to know which user have used which "rm" command..
Reply With Quote
  #8  
Old 7th July 2010, 08:50 AM
giulix's Avatar
giulix Offline
"Fixed" by (vague) request
 
Join Date: Oct 2005
Location: GMT+ 1
Posts: 2,950
linuxfedorafirefox
Re: How to run a shell script as a servive/daemon

Then you need two more things:
1) A loop (see while and for in the bash manual page)
2) A timeout (see sleep manual page)

Something like:

Code:
while(forever)
    append results of w command to output file
    wait n seconds
end
Reply With Quote
  #9  
Old 7th July 2010, 09:17 PM
assen Offline
Registered User
 
Join Date: Oct 2008
Posts: 492
linuxfedorafirefox
Re: How to run a shell script as a servive/daemon

Hi,

If you do not want to write a full safe-sustainable program, (daemon), you can use an external program to start your script and keep it alive.

You may simply run your script in background mode from rc.local (call it by name and add "&" after it).

You may have the init process start your script at boot time; it can also respawn it if it dies. With traditional SystemV system this is done in /etc/inittab. However, F13 has moved away and this will not do the trick; F13 is based on upstart.

If feeling curious, take a look at a tool called "svc" (aka "supervise") by D.J.Bernstein (http://cr.yp.to). It is designed to start, monitor and stop processes which are not daemons. ("Designed to run forever", sigh...)

WWell,
Reply With Quote
Reply

Tags
run, script, servive or daemon, shell

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
create a daemon for shell script mathboy314 Using Fedora 16 14th July 2010 07:52 PM
how to servive from my yum's crash? withcloud Using Fedora 2 5th May 2009 08:35 AM
call remote shell script within an expect script PhillyFloyd Programming & Packaging 2 16th October 2007 10:29 PM
starting a shell script inside a php script gw348 Using Fedora 6 23rd April 2007 09:30 PM
need to run script Bourne-shell script armen Using Fedora 4 4th April 2005 01:16 PM


Current GMT-time: 02:39 (Wednesday, 19-06-2013)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat