facing problem in starting a process in background using shell script.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting facing problem in starting a process in background using shell script.
# 1  
Old 04-15-2008
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 lineSmilie.

help awaited.
# 2  
Old 04-15-2008
Server daemons have their own conventions for how you start them. Read the tomcat documentation.
# 3  
Old 04-15-2008
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?
# 4  
Old 04-15-2008
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.
# 5  
Old 04-15-2008
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.
# 6  
Old 04-15-2008
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

# 7  
Old 04-16-2008
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Facing problem with Alias created through script.

Hi Guru's, I am creating alias for db instance running on a server through script, am able to create them based on /etc/oratab entries and can use successfully with the below script. #!/bin/bash SCRIPT_PATH=${HOME}/scripts/db/script... (3 Replies)
Discussion started by: venky.b5
3 Replies

2. Shell Programming and Scripting

Facing problem in the sqlldr & shell script

Guys i am facing two problems : (1) when i create the sql loader file the date format i m getting is this 28-DEC-11 12.03.14.107137 AM; for this i m using this script but unable to load the files trailing nullcols ( SERIALNO, AMOUNT, CLASS, MDN, VDATE "to_date(:TIMESTAMP, 'DD-MON-YY... (6 Replies)
Discussion started by: xal_kaushi
6 Replies

3. Shell Programming and Scripting

Running Shell Script in the cron, background process

Hi, i was looking for an answer for some trouble im having runing a script in the cron, thing is, that when i run it manually it works just fine. But when cron runs it, it just doenst work. I saw a reply on a similar subject, suggesting that the . .profile worked for you, but im kind of... (9 Replies)
Discussion started by: blacksteel1988
9 Replies

4. Shell Programming and Scripting

Problem facing command using shell

Dear Brothers! Need your help for the case where I am running one command on prompt and its giving us the correct output, but when i use the same command from shell its directs no output.:wall: the command on command prompt is ls -ltrh * | nawk '{if ($5~ '/$'M'/') print $9}' | grep -v... (1 Reply)
Discussion started by: jojo123
1 Replies

5. UNIX for Dummies Questions & Answers

Script to start background process and then kill process

What I need to learn is how to use a script that launches background processes, and then kills those processes as needed. The script successfully launches the script. But how do I check to see if the job exists before I kill it? I know my problem is mostly failure to understand parameter... (4 Replies)
Discussion started by: holocene
4 Replies

6. Shell Programming and Scripting

Creating background process for my shell

I actually posted this problem on a different forum, but figured this would be a more appropriate place to post it. OK so I've created my own shell, but I can't get the background process function to run properly! What I want to do is to run a process in the background, and also print when the... (2 Replies)
Discussion started by: hansel13
2 Replies

7. UNIX for Advanced & Expert Users

problem starting a process on solaris from other user

Hi Gurus, I have a server that has to users. 1) root 2)net1 there are several processes running on my server one of the process is CMIS_STACK process which is a compiled C code when this process goes missing then i restart this process manually in the following manner ... (2 Replies)
Discussion started by: asalman.qazi
2 Replies

8. Shell Programming and Scripting

Background Process Shell Scripting

I have a following program: echofunc() { filename=$1 echo "reading $filename" while read line do echo $line; sleep 6; done < $filename } split -5 new.dat ls x* > input.dat while read file do echofun $file & done < input.dat (3 Replies)
Discussion started by: dhieraj
3 Replies

9. Shell Programming and Scripting

How to include RETURN KEY with Background process "&" in Shell Script

Hello All, I am a newbie in Shell script programming, and maybe you can help me with my query. I need to write a shell script (mntServer.ksh) that will start a background process and also to be able to run another script. The mntServer.ksh script contains: #!/bin/ksh... (1 Reply)
Discussion started by: racbern
1 Replies

10. Shell Programming and Scripting

capture the process id when starting a background process

Hello all, How do I start a background process and save the process id to a file on my system. For example %wait 5 & will execute and print the process id. I can't figure out how to get it to a file. I've tried: > filename 0>filename 1>filename. Any assistance is most appreciated. Thanks, Jim... (10 Replies)
Discussion started by: jleavitt
10 Replies
Login or Register to Ask a Question