Sponsored Content
Top Forums Shell Programming and Scripting ksh behavior in scripts spawned w/nohup Post 303013589 by safedba on Friday 23rd of February 2018 11:24:50 PM
Old 02-24-2018
Ok...I ran a test and on my mac, everything works as it should, but not when it's spawned via dbms_scheduler on exadata....

This is the logic (it works)
This is the template:test.ksh
Code:
#!/bin/ksh
set -x
export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin
MAIN_DIR="/var/root/scripts"
cd $MAIN_DIR
DATE=$(date)
HOSTNAME=$(hostname)
FILE_CFG=$MAIN_DIR/simple_INSTANCE.cfg
FILE_LOG=$MAIN_DIR/simple_INSTANCE.log
sleep $(print $((RANDOM%100+1)))
typeset -i number_running=`ps -ef | grep runit_ | grep -v grep | wc -l` 
if [[ $number_running -eq 1 ]]
  then
    echo $number_running > $FILE_LOG
    nohup ./run_once_last.ksh &
fi

This is the cfg file (simple.cfg)

Code:
NCDP x y z
NCDT q r s
EDBP a b c
JUNO d e f

This code reads the template and creates as many ksh's and spawns as exists in the cfg (runit.ksh)

Code:
#!/bin/ksh
set -x
export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin
MAIN_DIR="/var/root/scripts"
cd $MAIN_DIR
DATE=$(date)
HOSTNAME=$(hostname)
FILE_CFG=$MAIN_DIR/simple.cfg
FILE_LOG=$MAIN_DIR/simple.log

function doit {
sed 's/INSTANCE/$1/g' < test.ksh > runit_$1.ksh
echo ${arr_cfg[@]}  > runit_$1.cfg
chmod +x runit_$1.ksh
nohup ./runit_$1.ksh &
}

cat ${FILE_CFG}|grep -v '#'|while read PARAMS
do
  set -A arr_cfg $PARAMS
  doit ${arr_cfg[0]} ${arr_cfg[@]}
done

Here's one genned:
Code:
#!/bin/ksh
set -x
export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin
MAIN_DIR="/var/root/scripts"
cd $MAIN_DIR
DATE=$(date)
HOSTNAME=$(hostname)
FILE_CFG=$MAIN_DIR/simple_$1.cfg
FILE_LOG=$MAIN_DIR/simple_$1.log
sleep $(print $((RANDOM%100+1)))
typeset -i number_running=`ps -ef | grep runit_ | grep -v grep | wc -l` 
if [[ $number_running -eq 1 ]]
  then
    echo $number_running > $FILE_LOG
    nohup ./run_once_last.ksh &
fi

This is run_once_last.ksh
Code:
#!/bin/ksh
set -x
export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin
MAIN_DIR="/var/root/scripts"
cd $MAIN_DIR
DATE=$(date)
HOSTNAME=$(hostname)
echo imdone > imdone.txt

It appears to work here, but when I schedule the job to run in oracle's dbms_scheduler, which kicks off the base job, everything works except the count check which would kick off the run_once_last.ksh

Obviously this is just an example, but it's all about attempting to run all oracle instances rman backups simultaneously but only run one tape backup, and that after the last backup that finishes completes....


BTW, I appreciate the sounding board. I'm not much of a scripter, I just hack away...
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Strange behavior from 'read' statements. (ksh - but could be same on other shells)

I'm getting rather frustrated with an interactive script I'm writing. The script is divided up, with section for setting variable at the top, then functions (which make up most of the script) then basically a line at the end which calls the first function- the program moves between the... (5 Replies)
Discussion started by: alexop
5 Replies

2. UNIX for Advanced & Expert Users

kill scripts which are started using nohup

i have scipt which is calling some other scripts and some built-in utilities like SED, find etc.. i started this script using nohup (e.g: nohup scriptname &) now i want to kill this script and all the child processes of this script. the problem is, process id of child processes are... (4 Replies)
Discussion started by: gfhgfnhhn
4 Replies

3. UNIX for Advanced & Expert Users

Find the process was run using nohup or ksh.

Hi, I want to write a script which should be run only on foreground. Is there any way that the script can check itself whether it was run using nohup or ksh and if the user runs the script using nohup then it should prompt the user to run it using ksh? If (The user triggers the script using... (4 Replies)
Discussion started by: RRVARMA
4 Replies

4. Shell Programming and Scripting

Ksh Associating scripts

Im writing a script in the Ksh, as the title suggests. OK so im sincerely tring to be lazy. Im trying to make a script that will use another file as a sort of variable library So basically i dont need to include the variables themselves, just want to make a reference to the file, so the... (2 Replies)
Discussion started by: Demon002
2 Replies

5. Shell Programming and Scripting

KSH script to run other ksh scripts and output it to a file and/or email

Hi I am new to this Scripting process and would like to know How can i write a ksh script that will call other ksh scripts and write the output to a file and/or email. For example ------- Script ABC ------- a.ksh b.ksh c.ksh I need to call all three scripts execute them and... (2 Replies)
Discussion started by: pacifican
2 Replies

6. Shell Programming and Scripting

ksh behavior change on RHEL5

I recently patched a RHEL5 host from 5.2 to 5.5. There are some scripts that simply do a ps and grep to check for itself before proceeding. I personally don't like the way the scripts are written and would have done it differently. Before I can proceed with patching the production servers, I... (12 Replies)
Discussion started by: bwhitehd
12 Replies

7. Shell Programming and Scripting

Behavior of Unix in calling 2 scripts simultaneously

Hi, I wanted to know the exact behavior of the shell scripts in the below scenario. I have 2 scripts - a.ksh and b.ksh Both these scripts call a 3rd script xyz.ksh. What will happen if both a.ksh and b.ksh run at the same time? What will happen if a.ksh starts 2-3 seconds before b.ksh?... (3 Replies)
Discussion started by: aster007
3 Replies

8. Shell Programming and Scripting

Process behavior different when spawned from single terminal

So this one just plain confuses me. I have a bunch of somewhat CPU intensive processes that all communicate using a shared memory region. Some of these programs are threaded and some also change the scheduling to FIFO or round robin. The good news is that everything works as long as I spawn... (3 Replies)
Discussion started by: talkingfennel
3 Replies

9. Shell Programming and Scripting

KSH - How to call different scripts from master scripts based on a column in an Oracle table

Dear Members, I have a table REQUESTS in Oracle which has an attribute REQUEST_ACTION. The entries in REQUEST_ACTION are like, ME, MD, ND, NE etc. I would like to create a script which will will call other scripts based on the request action. Can we directly read from the REQUEST_ACTION... (2 Replies)
Discussion started by: Yoodit
2 Replies

10. Shell Programming and Scripting

can a nohup'ed ksh script interact with user

I have a long running ksh script that I need to run with "nohup" in the backgound which is all well and good but at the very start of the script it needes to output to the screen to query the user and accept a response before continuing. Any thoughts on how to accomplish this other than... (11 Replies)
Discussion started by: twk
11 Replies
env(1)								   User Commands							    env(1)

NAME
env - set environment for command invocation SYNOPSIS
/usr/bin/env [-i | -] [name=value]... [utility [arg... ]] /usr/xpg4/bin/env [-i | -] [name=value]... [utility [arg... ]] DESCRIPTION
The env utility obtains the current environment, modifies it according to its arguments, then invokes the utility named by the utility op- erand with the modified environment. Optional arguments are passed to utility. If no utility operand is specified, the resulting environment is written to the standard output, with one name=value pair per line. /usr/bin If env executes commands with arguments, it uses the default shell /usr/bin/sh (see sh(1)). /usr/xpg4/bin If env executes commands with arguments, it uses /usr/xpg4/bin/sh (see ksh(1)). OPTIONS
The following options are supported: -i | - Ignores the environment that would otherwise be inherited from the current shell. Restricts the environment for utility to that specified by the arguments. OPERANDS
The following operands are supported: name=value Arguments of the form name=value modify the execution environment, and are placed into the inherited environment before utility is invoked. utility The name of the utility to be invoked. If utility names any of the special shell built-in utilities, the results are unde- fined. arg A string to pass as an argument for the invoked utility. EXAMPLES
Example 1 Invoking utilities with new PATH values The following utility: example% env -i PATH=/mybin mygrep xyz myfile invokes the utility mygrep with a new PATH value as the only entry in its environment. In this case, PATH is used to locate mygrep, which then must reside in /mybin. ENVIRONMENT VARIABLES
See environ(5) for descriptions of the following environment variables that affect the execution of env: LANG, LC_ALL, LC_CTYPE, LC_MES- SAGES, and NLSPATH. PATH Determine the location of the utility. If PATH is specified as a name=value operand to env, the value given shall be used in the search for utility. EXIT STATUS
If utility is invoked, the exit status of env is the exit status of utility. Otherwise, the env utility returns one of the following exit values: 0 Successful completion. 1-125 An error occurred. 126 utility was found but could not be invoked. 127 utility could not be found. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: /usr/bin +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ |CSI |enabled | +-----------------------------+-----------------------------+ /usr/xpg4/bin +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWxcu4 | +-----------------------------+-----------------------------+ |CSI |enabled | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ SEE ALSO
ksh(1), sh(1), exec(2), profile(4), attributes(5), environ(5), standards(5) SunOS 5.11 2 Jan 2002 env(1)
All times are GMT -4. The time now is 04:19 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy