The UNIX and Linux Forums  

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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Background Process Shell Scripting dhieraj Shell Programming and Scripting 3 04-12-2008 11:16 AM
How to include RETURN KEY with Background process "&" in Shell Script racbern Shell Programming and Scripting 1 03-11-2008 03:30 AM
Facing issue in Solaris OS in crontab for running shell script mabrar Shell Programming and Scripting 2 11-02-2007 02:32 AM
Background shell script Moofasa Shell Programming and Scripting 5 05-12-2005 06:23 PM
capture the process id when starting a background process jleavitt Shell Programming and Scripting 10 04-04-2002 05:04 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-14-2008
Registered User
 

Join Date: Apr 2008
Posts: 4
Stumble this Post!
facing problem in starting a process in background using shell script.

hey all,

i am working on sun solaris machine and i want to start a process in background using shell script (actually i wanna start tomcat server using shell script). please dont tell me that append a & at last because this is not working in the shell script. i have also used nohup and redirected the output to /dev/null but all tries going into waste because every time the process is starting in forground and script hangs at that line.

help awaited.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 04-15-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
Stumble this Post!
Server daemons have their own conventions for how you start them. Read the tomcat documentation.
Reply With Quote
  #3 (permalink)  
Old 04-15-2008
Registered User
 

Join Date: Apr 2008
Posts: 4
Stumble this Post!
but i had tried to start other processes also in background and result was same. have anyone ever tried to start a process in background using shell script. can i start a new shell by shell script?
Reply With Quote
  #4 (permalink)  
Old 04-15-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
Stumble this Post!
Yes, somebody has ever tried to start a process in the background. The problem is, it will foreground if it requires tty input. An interactive shell will thus foreground when it wants to read input. If you disable that, you can run it in the background just fine.

Code:
sh </dev/null &
(It finishes pretty quickly because it has nothing to do, though. :^)

Servers usually have their own start-up scripts which often require root privileges. Depending on your architecture, look for something like /etc/init.d/tomcat (for a Debian-type system) or /etc/rc/tomcat or some such.
Reply With Quote
  #5 (permalink)  
Old 04-15-2008
Registered User
 

Join Date: Apr 2008
Posts: 4
Stumble this Post!
but the processes which i m trying to run by shell script doesnt require any input and still that processes are not going into background.

one more thing i want to say is that, these all processes are going into background successfully when i ran that processes at command prompt directly. the problem in coming when i m trying to run that processes through script.
Reply With Quote
  #6 (permalink)  
Old 04-15-2008
Registered User
 

Join Date: Apr 2008
Posts: 5
Stumble this Post!
If it helps you, here I paste one of my scripts where I launch a query script and send CR while it's running for my connection not to timeout. Hope it helps:
Code:
#!/bin/ksh
#set -x
# lanzamiento del script de consulta
/opt/bind/usr/sbin/loader.sh $1 $2 &

#   Envio de un CR cada 3 segundos  durante 1,5 minutos
#   para evitar el corte por temporizacion
#
#
PID=$!
#echo $PID
cont=0
while [ `ps -p $PID|grep $PID|wc -l` -eq 1 -a  $cont -lt 30 ]
  do
    echo
    sleep 3
    cont=`expr $cont + 1`
  done

#   Verificacion de si ha temporizado o no el proceso
#
#
if [ `ps -p $PID|grep $PID|wc -l` -eq 1 ]
   then
   	kill -9 $PID
        sleep 2
        echo "ERROR: La consulta no se ha completado correctamente"
        exit 1
   else
        echo "Consulta realizada con exito"
	exit 0
fi
Reply With Quote
  #7 (permalink)  
Old 04-16-2008
Registered User
 

Join Date: Apr 2008
Posts: 4
Stumble this Post!
thanx for the script!!!

as long as i understand, it seems that this is calling another script in background but i wanna ask one thing here is that this called script is an infinite script or it return after some time. and are you sure that this called script in going into background?

one more thing, i think there can be difference in running these script on unix machine and solaris machine? is this true?

reply awaited.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
solaris

Thread Tools
Display Modes




All times are GMT -7. The time now is 09:05 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0