LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-30-2008, 04:12 AM   #1
sharu99
LQ Newbie
 
Registered: Oct 2008
Posts: 15

Rep: Reputation: 0
Question How to run the /usr/sbin/in.tftpd script in the background continuously?


Hi,

I am writing a shell script which will check if in.tftpd service is running and will start it, if its not running. i.e. it executes the /usr/sbin/in.tftpd script to start the tftpd service. But when this command is executed in the background with the & symbol, it gets terminated when i hit the enter key. The script is attached below :-

#!/bin/bash
set -x
touch /tftpd_check/tftp_current
ps -ef |grep -i in.tftpd > /tftpd_check/tftp_current
a=`wc -l /tftpd_check/tftp_current | cut -d " " -f1` >> tftpd_count
echo "hello $a"
if [ $a -gt 1 ]
then
echo "tftp is running" >> /tftpd_check/tftp_msg
date >> /tftpd_check/tftp_msg
else
echo " I am in else block"
/usr/sbin/in.tftpd &

echo "END"
rm -rf /tftpd_check/tftp_current
fi
~


Can you please suggest some tips so that the tftpd service runs continuously??
 
Old 10-30-2008, 04:40 AM   #2
maradnus
Member
 
Registered: Oct 2008
Location: Yellagiri Hills
Distribution: Fedora
Posts: 87

Rep: Reputation: 15
Lightbulb Simple problem

Hi friend

That means the script has been executed ie finished its job.

Run the the following code:
<your script will be executed for every 15 minutes>
Code:
while :
do
      sh scriptname.sh
      sleep 900 
done &
have a good day
 
Old 10-30-2008, 05:03 AM   #3
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670
If this is an actual service, it will probably run as root and it would be better if you used the "service" command or /etc/init.d/ startup script (or a rc* script in SuSE) to start the script. The scripts to start a service will have a status argument that will allow you to monitor whether the service is running.
You can use the return value of the script to decide whether it needs to be started or not.
For example:
Code:
/usr/sbin/rcsmb status >/dev/null && echo running || /usr/sbin/rcsmb start
Starting a service needs to be done as root, so you might want to create a cron job to run periodically. You will need to redirect output (both stdin and stdout) to /dev/null or a log for a cron job.

In my example the part between the && and || is superfluous and you could do without it unless you wanted to log success. But that would build up a large log file unnecessarily.
Code:
/usr/sbin/rcmysql status 2&>1 1>/dev/null || /usr/sbin/rcmysql start
Code:
jschiwal@hpmedia:~> sudo /sbin/service mysql status && echo running || echo notrunning
Checking for service MySQL:                                           running
running
jschiwal@hpmedia:~> sudo /sbin/service xfs status && echo running || echo notrunning
Checking for X Font Server:                                           unused
notrunning

Last edited by jschiwal; 10-30-2008 at 05:10 AM.
 
Old 10-30-2008, 05:41 AM   #4
sharu99
LQ Newbie
 
Registered: Oct 2008
Posts: 15

Original Poster
Rep: Reputation: 0
Smile

Quote:
Originally Posted by maradnus View Post
Hi friend

That means the script has been executed ie finished its job.

Run the the following code:
<your script will be executed for every 15 minutes>
Code:
while :
do
      sh scriptname.sh
      sleep 900 
done &
have a good day
In ran for some time. But it stopped again....I want the script to check if tftpd is running and start it if not.... else just print "tftpd is running"

Last edited by sharu99; 10-30-2008 at 05:45 AM. Reason: didn't work
 
Old 10-30-2008, 09:55 AM   #5
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,117
Blog Entries: 2

Rep: Reputation: 113Reputation: 113
Are you sure your in.tftpd isn't being run by an inetd program? If it is then it'll only run when someone is accessing it, the inetd program will spawn it again when it is needed.
 
Old 10-30-2008, 11:03 AM   #6
sharu99
LQ Newbie
 
Registered: Oct 2008
Posts: 15

Original Poster
Rep: Reputation: 0
Hey I was able to create the script and it works fine. Now i want to schedule it using crontab.
The cron job is not getting executed. But when i execute it manually from the shell, it works fine.

The cron job entry is as follows :-

3 8 * * * sh /tftpd_check/tftpd_check.sh


I want to cron job to run at 8.03 in the morning every day.
Please let me know what has to be checked in this.
 
Old 10-30-2008, 08:00 PM   #7
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
If cron has a problem, it normally emails either the conjob user or root with the problem details.
Try mail or mailx from the cmd line to check.
Usually (for a newbie) its not knowing that cron has a very minimal env, which means its highly advisable to provide the full/absolute path to all cmds/files mentioned in the cron job.
 
Old 10-31-2008, 12:22 AM   #8
sharu99
LQ Newbie
 
Registered: Oct 2008
Posts: 15

Original Poster
Rep: Reputation: 0
Smile

Quote:
Originally Posted by chrism01 View Post
If cron has a problem, it normally emails either the conjob user or root with the problem details.
Try mail or mailx from the cmd line to check.
Usually (for a newbie) its not knowing that cron has a very minimal env, which means its highly advisable to provide the full/absolute path to all cmds/files mentioned in the cron job.

Hi,

I saw the below entry when i ran the mail cmd, to check the mails..
Does this suggest something?

--------------------- Cron Begin ------------------------

**Unmatched Entries**
STARTUP (V5.0)
STARTUP (V5.0)
STARTUP (V5.0)

---------------------- Cron End -------------------------
 
Old 10-31-2008, 01:20 AM   #9
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
Was there anything else?
Is this the same user as you're trying to run the daemon as?
What distro/version?

To be honest, I think you'd be better off using the super-daemon (xinetd or inetd) to do all this for you.
In most distros its the dir

/etc/xinetd.d

and contents.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Samba --> nobody run "add user script = /usr/sbin/useradd ....." ??!! Unconfigured Fedora 1 02-23-2006 05:54 AM
Samba --> nobody run "add user script = /usr/sbin/useradd %u ....." ???? Unconfigured Linux - Software 1 02-21-2006 10:01 AM
Unable to run /usr/sbin/pppd. --> Check permissions [solved] flosch Linux - Networking 0 05-05-2004 10:08 AM
Can't find adsl-setup script in /usr/sbin caddie Linux - Newbie 1 09-11-2002 11:38 AM


All times are GMT -5. The time now is 10:37 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration