The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
error : kernel panic: No init found amitpansuria Red Hat 2 10-04-2007 07:08 AM
start script from - execute init 6 (not as root) soshell SCO 4 02-08-2007 02:12 AM
Fail to run init-script from crontab indo1144 UNIX for Advanced & Expert Users 5 09-14-2005 11:47 AM
Init 6 & Init 0 problem sc2005 UNIX for Advanced & Expert Users 6 09-06-2005 11:36 AM
creating a service in init.d collins UNIX for Advanced & Expert Users 2 09-30-2004 11:28 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-14-2007
pankajd pankajd is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 19
error in init script of dnotify service

fallowing code is for init script for dnotify service
# !/bin/bash
# DESCRIPTION
#Process name-dnotify
# Dnotify startup script:-
# Init/rc scripts are bash scripts used to manage services like dnotify.
# Dnotify (directory notification) is a utility for monitoring filesystem events i.e.
# Dnotify is a file system event monitor for the Linux kernel,
# A init script for dnotify provides feature for starting , stopping , getting status
# and restarting a service.


# Checkng that we are root ... so non-root users stop here
[ `id -u` = 0 ] || exit 1

#flush filesystem buffer
sync

# check for Source function library.
if [ -f /etc/rc.d/init.d/functions ]
then
. /etc/rc.d/init.d/functions
else
echo "$0: source function library doen't exit?.."
exit 1
fi

sync

#variable declaration
PATH_TO_DNOTIFY=/usr/bin/dnotify
PBS_JOBS_DIR=/usr/spool/PBS/server_priv/jobs/
COPY_COMMAND=/usr/local/bin/copyFile.sh
DIR_CP=/usr/spool/PBS/reports
PID_FILE=/var/run/dnotify.pid
LOCK_FILE=/var/lock/subsys/dnotifyd
RETVAL=0

#check for dnotify service file
# [ -x $PATH_TO_DNOTIFY ] || exit 0
if [ ! -x $PATH_TO_DNOTIFY ]
then
echo "$0:dnotify service is not present?.."
exit 1
fi

#check for PBS_JOBS_DIR directory
if [ ! -d $PBS_JOBS_DIR ]
then
echo "$0:directory to be monitored is not present?.."
exit 1
fi

#check for copy command script file
if [ ! -x $COPY_COMMAND ]
then
echo "$0:copy command script file is not present?.."
exit 1
fi


# check whether dnotify service is already started;if it is,then throw error otherwise start the service
start() {
if [ -f $LOCK_FILE -a -f $PID_FILE ]
then
echo -e "Error:dnotify is already running......"
exit 0
else
echo -e $"Starting dnotify......."
sync
#run dnotify service with create event i.e. -C directory to be monitored i.e.PBS_JOBS_DIR and execute copy command i .e. -e $COPY_COMMAND

$PATH_TO_DNOTIFY -C $PBS_JOBS_DIR -e $COPY_COMMAND &

RETVAL=$?
# creating lock file
[ $RETVAL -eq 0 ] && touch $LOCK_FILE

#add date to lock file
date > $LOCK_FILE
#add pid of dnotify to pid file
pidof dnotify > $PID_FILE
RETVAL=$?

sync

#creating test file in PBS_JOBS_DIR
[ $RETVAL -eq 0 ] && touch $PBS_JOBS_DIR/test_file11
RETVAL=$?

#taking timestamp and filename
if [ -e $PBS_JOBS_DIR/test_file11 ]
then
[ $RETVAL -eq 0 ] && q=`ls -l $PBS_JOBS_DIR/test_file11 |cut -d' ' -f7,8,9`
RETVAl=$?
[ $RETVAL -eq 0 ] && q1=`ls -l $DIR_CP/test_file11 |cut -d' ' -f7,8,9`
RETVAl=$?
fi

#comparing strings to verify whether service is functional or not
if [ "$q" = "$q1" ]
then
echo -e "dnotify service is started and is functional..."
else
echo -e "dnotify service is not functional..."
fi

#removing test file
[ -e $PBS_JOBS_DIR/test_file11 ] && rm -f $PBS_JOBS_DIR/test_file11
[ -e $DIR_CP/test_file11 ] && rm -f $DIR_CP/test_file11
sync
fi
return $RETVAL
}


#option for stopping dnotify
stop() {
#checking for lockfile nad pid file
if [ -f $LOCK_FILE -a -f $PID_FILE ]
then
echo -e "Stopping dnotify......"

#killing process i.e.stopping service
cat $PID_FILE | xargs kill -9

#stopping other dnotify process instances running
ps -aef | grep dnotify | awk '/dnotify/ {kill -9 $2}'

RETVAL=$?

#removing lockfile
[ $RETVAL -eq 0 ] && rm -f $LOCK_FILE

#removing pidfile
rm -f $PID_FILE

echo -e "dnotify service is stopped. "

return $RETVAL
else
echo -e "dnotify service is alredy stopped....."
fi
}

#option for knowing status
status () {
if [ -f $LOCK_FILE -a -f $PID_FILE ]
then
echo -e "STATUS : dnotify is running......"
echo -e "Date and time when dnotify service is started is : "
#displaying service information
cat $LOCK_FILE
echo -en "Pid of dnotify is : "
cat $PID_FILE
else
echo -e "STATUS : dnotify is not running...."
fi
exit 0
}

#Handling arguments
case "$1" in
start)#call to start function
start
;;
stop)#call to stop function
stop
;;

restart)#first call to start function and then to stop function
echo "restarting dnotify..."
stop
start
;;

status)#call to status function
status
;;

condrestart)
#This option call stop and start, but only if the service is currently running
if [ -f $LOCK_FILE ]
then
stop
start
else
echo "ERROR:check that service is running...."
fi
exit 0
;;
*)#invalid arguments passed will see this
echo $"Usage: $0 {start|stop|status|restart|condrestart}"
exit 1
esac

now i am getting error like this when i execute script with start option
Starting dnotify.......
ls: /usr/spool/PBS/reports/test_file11: No such file or directory
dnotify service is not functional...
[root@tb0 ~]# cp: cannot stat `/usr/spool/PBS/server_priv/jobs/test_file11': No such file or directory
/usr/bin/dnotify: child terminated with non-zero status
help asap
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:44 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0