Sponsored Content
Special Forums UNIX and Linux Applications How to check if process is running? Post 302417237 by ladyAnne on Thursday 29th of April 2010 04:41:15 AM
Old 04-29-2010
---------- Post updated at 03:41 AM ---------- Previous update was at 01:23 AM ----------

[/COLOR]I have altered my script a bit .... now I get syntax errors.

To me this script looks fine.

Can somebody please assist me in finding what the problem is.

Thank you

Code:
 
#!/bin/bash
#---------------------------------------------------------------------------------------------------------------------- 
#This script allows the user to import a dsx file 
#
# Usage:
#./import.sh -s -d -r -f
#
#-----------------------------------------------------------------------------------------------------------------------
dbname="$dbname"
dsn="$dsn"
dsxfile="$dsxfile"
rangechk="$rangechk"
verbose=""
reverb=""
module=`basename $0`
DSXLOG_MODULE=$module 
export DSXLOG_MODULE
dsxdir="/var/local/dsx/import"
dsximp="/usr/local/bin/dsximp.exe"
dsxpids="/var/run"
function rm_pidfile
{ 
rm -f $dsxpids/$module.pid 
} 
function is_running 
{ 
# File does not exist, we can run 
[ -f $dsxpids/$module.pid ] || return 1 
# Read PID from file 
read PID < -f $dsxpids/$module.pid 
# File exists but process does not. 
[ -d /proc/${PID} ] || return 1 return 0 
} 
#------------------------------------------------------------------------#
# This guarantees other scripts will wait for each other 
# before checking the pidfile. otherwise one might create the PID 
# file while we're not looking. 
#------------------------------------------------------------------------#
while ! mkfifo -f $dsxpids/$module.lock 2> /dev/null 
do sleep 1 done 
#------------------------------------------------------------------------#
# beyond this point, /var/run/import.sh.lock exists and belongs to us. 
# Other instances of the script will loop. 
#------------------------------------------------------------------------#
if is_running then echo "An instance(PID ${PID}) is already running"
rm -f $dsxpids/$module.lock 
exit 1
fi
echo "$$" > -f $dsxpids/$module.pid
trap "rm_pidfile" EXIT
rm -f $dsxpids/$module.lock
while true do sleep 1 done
function displayHelp()
{
echo ""
echo " Usage: ./import.sh [ -s -d -r -f ]"
echo ""
echo " -s, --dsn identified by the Data Source Name "
echo " -d, --dbname identified by the Database Name "
echo " -r, --rangechk specify range checking option " 
echo " -f, --dsxfile identified by the file in dsx format "
echo " -h, --help identified by the help menu "
echo ""

}
while getopts " s: d: r: f: e h " option
do
case $option in

f ) dsxfile="$OPTARG";;
d ) dbname="$OPTARG";;
s ) dsn="$OPTARG";;
r ) rangechk="$OPTARG";;
e ) verbose="--verbose"
reverb="--echo";;
h | ? | * ) displayHelp;exit;;

esac;
done
if [[ $# -eq 0 ]]; then
displayHelp
exit 1
fi

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to check if another instance of the process is running

Hi, I am writing a shell script to invoke a C++ program. Before I start the C++ program (oi7loadbalancer), I am checking if the process is already running. I start the process only if it is not already running. I have the following check in my script. proccount=`ps -f -u $USER_NAME | grep... (8 Replies)
Discussion started by: sim
8 Replies

2. Shell Programming and Scripting

check process running

I have this script: ------------------------------------------------------- #!/bin/ksh # if ] || ] then echo "Executing main_load.sh script" /usr1/psc_load/jobs/cron/main_load.sh "ods" else echo "File not found, do nothing" fi exit 0 ... (4 Replies)
Discussion started by: rose1207
4 Replies

3. UNIX for Advanced & Expert Users

how to check how long the process has been running.

I have a requirement to check how long a process is running on unix system.If i use ps -ef i am getting the following message guest 2453638 1998920 0 16:16:05 - 0:00 dsapi_slave 9 8 0 but this is showing only time not the date.Can any one please advice me any script to find out how... (2 Replies)
Discussion started by: ukatru
2 Replies

4. UNIX for Advanced & Expert Users

How to check since when (for how long) a particular process is running ?

How do I check if a particular process is running from a certain date and time ? (2 Replies)
Discussion started by: hpuxlxboy
2 Replies

5. Shell Programming and Scripting

Check if Process is running

Hi , I have a csh code below which check the process if it's running. Can any expert advise me on the following: 1) what does this notationmean ">!" and how is it different from the append ">" notation ? 2) how does "setenv" work in this code ? # Check whether there is a running... (3 Replies)
Discussion started by: Raynon
3 Replies

6. UNIX for Dummies Questions & Answers

Command to check if a particular process is running

Hi What is the best command to check if a particular process is running in a linux server or not To check any java process, I use the below command. ps -ef |grep jvm When I execute the above command, it lists me all the processess . The above command should ideally return only the... (6 Replies)
Discussion started by: vr3w3c9
6 Replies

7. Programming

How do I check if a process is running in C

How to I check if a process is running in C? I'm trying to use ps aux |grep "process name" but failing in doing that. How do I do that? Thanks, (1 Reply)
Discussion started by: cprogdude
1 Replies

8. Shell Programming and Scripting

need to check if the process is running

Hi, I check if the process is running or not using the below. /usr/ucb/ps auxww | grep 109 |grep rmi | awk '{print $2}' 9718 Thus we see 9718 is the PID. It return blank if the process is not running. I need to perform some action if the process is not running and leave it if... (8 Replies)
Discussion started by: shifahim
8 Replies

9. UNIX for Dummies Questions & Answers

How a process can check if a particular process is running on different machine?

I have process1 running on one machine and generating some log file. Now another process which can be launched on any machine wants to know if process1 is running or not and also in case it is running it wants to stream the logs file generated by process1 on terminal from which process2 is... (2 Replies)
Discussion started by: saurabhnsit2001
2 Replies

10. Shell Programming and Scripting

Looping to check the currently running process.

Hi Gurus, t=`ps -u irb|grep -v grep|grep BSNL_PAYMENT_C` echo $t if then echo $? echo "Process Creation is Running ...." else echo "Process went down at $dat $tim" fi How would i use loop so that the script continously checks for the current status of this process.... (1 Reply)
Discussion started by: ankitknit
1 Replies
fsdaemon(1M)															      fsdaemon(1M)

NAME
fsdaemon - pass-through daemon for processing system commands SYNOPSIS
fork] DESCRIPTION
The is a user level daemon that provides a mechanism to pass information between applications and common commands and library functional- ity, allowing certain applications to dynamically add functionality to a system. This is currently only supported for the class of APIs, such as: The API are not yet publicly available, but the commands that use the mentioned APIs depend on this daemon to always be running in the HP- UX environments. Options When is started, indicates whether it should fork a child process and exit the parent process or run just as the parent process and not return. A value of 1 for fork will make fork and exec a child process and then cause the parent process to exit. Kills the current running instance of Tests and waits until is ready to process commands. There is a window where could be started and not yet setup to process commands. The caller should invoke separately with the option to block until is ready to process commands. The entries to start are in the file. These entries be present to ensure correct functionality of the system. They should appear as one of the first entries in placing entries before entries in is dangerous and unsupported. The following are some of the HP-UX commands that use via the above APIs: and RETURN VALUE
: 0 Successful start of If invoked with the option, 0 is always returned. >0 Errno of failure that caused to fail to start. This applies only if was started with the option. ERRORS
If is not running, the errno will be returned by an application that invokes these APIs. If this happens, please see your system adminis- trator to make sure is properly running. EXAMPLES
To start such that it can be invoked without permanently blocking the calling process: To kill the currently running instance of To check to see if the currently running instance of is ready and able to process requests sent to it: The following entries for starting should appear in the file: WARNINGS
The APIs are not yet publicly available, but the commands that use the mentioned family of APIs depend on this daemon to always be running on HP-UX environments. The administrator is not expected to invoke the command from the shell prompt; it should always be started via an entry in This manpage is provided for administrator's trouble shooting purposes, and to allow the system administrator to repair the entries for this daemon in case of corruption. The interface/options provided in this manpage are HP-UX release specific, and may be different in future releases. AUTHOR
was developed by HP. SEE ALSO
fstyp(1M), mkboot(1M), mount(1M), fstatfsdev(3C), fstatvfsdev(3C), statvfsdev(3C), statfsdev(3C), inittab(4). fsdaemon(1M)
All times are GMT -4. The time now is 10:01 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy