Problems running scripts in the background


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problems running scripts in the background
# 1  
Old 08-30-2016
Problems running scripts in the background

Hi

Could someone offer some help on this problem I've got with running a background process.

As part of a script that does a stop/start/status for a piece of software called SAS, the following extract is from part of the start step.

My issue is that when the script is run, the control remains with the script until I press RETURN. Clearly I don't want to have to do this.


Code:
   start2_tag)
         cd $CONFIGDIR
         . $SASENV
         SASROOT=$SASROOT
         export SASROOT

         # Source usermods file
         . $CONFIGDIR/ObjectSpawner_usermods.sh

         eval "nohup $COMMAND $CMD_OPTIONS -sasSpawnerCn \"$SPWNNAME\" -xmlconfigfile $OMRCFG -logconfigloc $CONFIGDIR/logconfig.xml ${USERMODS}> $LOGSDIR/ObjectSpawner_console_sascompute2.log 2>&1 &"
         pid=$!
         echo $pid > $CONFIGDIR/$SERVER_PID_FILE_NAME
         echo "Spawner is started (pid $pid)..."
         trap 'kill $pid' 2 3 15
         wait $!
         rm "$CONFIGDIR/$SERVER_PID_FILE_NAME"
         echo "Spawner is stopped"
         echo "Log files are located at: $LOGSDIR"
         ;;

Running the code:

Code:
sas@SASCOMPUTE2:/sas/compconfig/Lev1> ./sas.servers.comp2 start
Starting HQ Agent...... running (6494).
sas@SASCOMPUTE2:/sas/compconfig/Lev1> Spawner is started (pid 6815)...

I have to hit RETURN to get the prompt back to the command line.

Ultimately I want this startup step running from another server as part of a number of processes starting at the same time on various servers.

ie..

Controlling script:
Code:
su - sas -c "/sas/metaconfig/Lev1/sas.servers start"
su - sas -c "ssh sas@sascompute1 /sas/compconfig/Lev1/sas.servers.comp1 start"
su - sas -c "ssh sas@sascompute2 /sas/compconfig/Lev1/sas.servers.comp2 start"
su - sas -c "ssh sas@sasmid /sas/midconfig/Lev1/sas.servers start"

..and on the sascompute2 server:

Code:
#!/bin/bash

# first the environment manager agent
/sas/compconfig/Lev1/Web/SASEnvironmentManager_SASCOMPUTE2/agent-5.8.0-EE/bin/hq-agent.sh $@

# then the spawner
/sas/compconfig/Lev1/ObjectSpawner2/ObjectSpawner.sh $@

The problem code at the top is from the ObjectSpawner.sh script.

Any help much appreciated.

Gavin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Run scripts in background one by one

Hello all, Can someone help with one script? I have as example 3 scripts 1.sh sleep 60 & sleep 60 & sleep 10 & sleep 80 & sleep 60 & 2.sh sleep 40 & sleep 5 & sleep 10 & sleep 70 & sleep 60 & 3.sh (2 Replies)
Discussion started by: vikus
2 Replies

2. Shell Programming and Scripting

How to run scripts sequentially in background?

Hi , I have prepared the following shell script to run the hqls in background. These scripts are running Parallel but I want to run the hqls sequentially in background. cat >cc_script.ksh nohup hive -hiveconf rrdt=2016-06-12 -f /home/files/cust1.hql > home/log/cust1.log 2>&1 & nohup hive... (6 Replies)
Discussion started by: ROCK_PLSQL
6 Replies

3. Shell Programming and Scripting

Running scripts in background

Hi, below is my master script wihch inturn runs 2 scripts in background #master_script.sh ./subscript1.sh & ./subscript2.sh & executed the master_script.sh from unix command prompt $ ./master_script.sh it is executing the subscripts and they are completing fine, however master_script.sh is... (2 Replies)
Discussion started by: JSKOBS
2 Replies

4. Shell Programming and Scripting

[BASH] Script to manage background scripts (running, finished, exit code)

Heyas, Since this question (similar) occur every now and then, and given the fact i was thinking about it just recently (1-2 weeks) anyway, i started to write something :p The last point for motivation was... (17 Replies)
Discussion started by: sea
17 Replies

5. Shell Programming and Scripting

background scripts run-help

Looking for a logic where say i have a script called parent_script which is used to call other 4 to 5 child scripts in background as.. cat parent_script # containing 65 lines 1 2 .. 35 while read child_script 36 do 37 ./child_script_name& 38 done< ${SCRIPT_LISTS} 39 40 # Need to have... (2 Replies)
Discussion started by: michaelrozar17
2 Replies

6. Shell Programming and Scripting

Simutaneous scripts within a background task

Hi, I have a script that polls a directory using inotifywait. This script is always running in the background. Within that script, I have 2 commands that need to run simultaneously. When those scripts are finished, I have to fire off a 3rd. The problem is, the 3rd script is never being... (0 Replies)
Discussion started by: gseyforth
0 Replies

7. Shell Programming and Scripting

Running scripts within scripts from cron

Hi all, I have set up a cron job which calls another shell script shell script which in turn calls a Java process. The cron tab looks so. 0,30 7-18 * * 1-5 /u01/home/weblogic/brp/bin/checkstatus.sh >> /u01/home/weblogic/logs/checkstatus.log The checkstatus.sh scripts looks like this. ... (4 Replies)
Discussion started by: sirbrian
4 Replies

8. Shell Programming and Scripting

running in background

i have a script called server.sh. how to run this script in backgroung using nohup command (5 Replies)
Discussion started by: ali560045
5 Replies

9. Shell Programming and Scripting

exit status of Invoking two or more scripts in background

I have a sript which is going to trigger other 3 scripts in background simultaneously for eg: Main Script:(main.sh) ----------- sh a.sh & sh b.sh & sh c.sh & How to catch the exit status and store it in a variable for all those three scripts in main script. Is there any other way of... (4 Replies)
Discussion started by: Omkumar
4 Replies

10. UNIX for Dummies Questions & Answers

problems with ctrl-z, to switch foreground, background

my shell is /sbin/sh. i added stty susp '^Z' with the intention of being able to switch between foreground and background. but the result was strange. i had 2 servers. one is sun the os is 8 and the other is hpux v11. both of them had the same shell. but on hpux, it works perfectly fine while... (9 Replies)
Discussion started by: yls177
9 Replies
Login or Register to Ask a Question