Sponsored Content
Full Discussion: jump in a .KSH batch
Operating Systems AIX jump in a .KSH batch Post 302253970 by bakunin on Monday 3rd of November 2008 08:38:47 AM
Old 11-03-2008
Quote:
Originally Posted by enge
can i set the value of the run variabile via cobol program?
The "$?" is a special variable called "Error code" or "Error level". It is an (unsigned short) integer value. A value of "0" (which also happens to be a logical "TRUE" in "if"-conditions) is considered to mean "normally finished program", every code other than that means one of several erroneous conditions.

Try it yourself:

Code:
cat /some/existing/file >/dev/null ; echo $?        # will print "0"
cat /some/non-existing/file >/dev/null ; echo $?    # will print "1"

The output of "cat" is directed to /dev/null (the "black hole" of the OS) so you won't notice its operation. It still gives back an error code to the OS when it terminates and this is what you see with "echo $?". The "1" in the second case is because "cat" cannot find the file you are asking it to print.

Having said this: Yes, you can use this mechanism to pass messages to your calling program. As COBOL is a compiled language you will have to use the exit()-systemcall, which will take an (unsigned integer) value, which will be passed as error level.

You can NOT pass arbitrary messages (like text, etc.) via this mechanism, so the functionality is quite limited. If you want to pass longer output to other programs you should not use this mechanism anyway, but other means like writing to <stdout>. If you write to <stdout> you can use the pipeline construct to pass input to another program, which will read it from its <stdin>.

Code:
program1 | program2

Means simply that "program1" creates some output. This output could go into a file, a device, whatever. "program2" gets its input from <stdin>. Normally this will be you typing away, it could also be a file, a device, etc.. In this special case the OS is connecting <stdout> of "program1" with <stdin> of "program2" this way establishing a (one-way) communication. So in fact the pipeline can be thought of a shortcut to:

Code:
program1 > file
program2 < file

just without the intermediary file in between. Notice, btw., that the error code of a pipeline is always the error code of the last command. If in our example program1 returns "0" and program2 returns "1" then "$?" would yield "1". In the second example with the intermediary file you could separately get the the error codes of program1 and program2, but i get carried away....

I hope this helps.

bakunin
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Knoppix ---> Slackware the big jump, should I?

yea, I'm a really dummie, I have been using Knoppix for a while on a bootable disk, but wanting to switch to Slackware, is this a good decision? could any of you link me to a slackware downloadable site? thanks -Jace:D (7 Replies)
Discussion started by: Jace
7 Replies

2. Shell Programming and Scripting

how to convert unix .ksh script to windows .batch script

I am using awk in my .ksh script but when I am trying to run in windows its not recognising awk part of the ksh script , even when I changed it to gawk it does not work, this is how my .ksh and .bat files look like. thanx. #!/bin/ksh egrep -v "Rpt 038|PM$|Parameters:|Begin |Date: |End... (1 Reply)
Discussion started by: 2.5lt V8
1 Replies

3. Shell Programming and Scripting

Jump to a specific place in a file?

If I cat a file And want to go to the first instance of a particular value - what command would I use? And then from that point where I jumped to search for another value - but only search from that point forward not before the file? Thanks~ (2 Replies)
Discussion started by: llsmr777
2 Replies

4. Shell Programming and Scripting

[bash] jump from one txt file to another

Hi all, I need to create a bash script that reads a txt file on a remote (Windows 2003) server, gets the IP-addresses out of it and then fetches the folders to copy out of another txt file. (all files are auto-generated) The IP addresses that don't have a folder_list file should be ignored. At... (31 Replies)
Discussion started by: laurens
31 Replies

5. Shell Programming and Scripting

Executing KSH batch file located in specific folder

Ok apologies if this is trivial or doesn't make sense but I am quite new to korn shells; So I have a .ksh batch file located in a folder of my choosing, I want to run this file in a korn shell. The problem though is that I want to get VBA code to do this. I have (VBA) code which opens command... (1 Reply)
Discussion started by: cjsewell
1 Replies

6. Shell Programming and Scripting

HowTo translate KSH Scripts to DOS Batch Files ?

Hi there, in near future I have to change my work surrounding from HP UNIX to Windows Vista (great to get rid of old hardware :), but bad to loose UNIX :( ). As I heavily use KSH scripts to do my job, I was wondering, if there is any HowTo available, supporting me in re-writing the scripts to... (4 Replies)
Discussion started by: Joe-K7
4 Replies

7. Shell Programming and Scripting

how to jump a shell !!

Hi, can someone point out a solution to my problem below. Within a shell script TEST.ksh I have to run two commands CmdA & CmdB one after the other as below. ------------- TEST.ksh #!/usr/bin/ksh A B ------------- I am running this script from KSH with PID 12345 as below. ... (5 Replies)
Discussion started by: krishnaux
5 Replies

8. Shell Programming and Scripting

Executing a batch of files within a shell script with option to refire the individual files in batch

Hello everyone. I am new to shell scripting and i am required to create a shell script, the purpose of which i will explain below. I am on a solaris server btw. Before delving into the requirements, i will give youse an overview of what is currently in place and its purpose. ... (2 Replies)
Discussion started by: goddevil
2 Replies

9. Shell Programming and Scripting

Jump to next element in a loop

Hi, i want the loop to move to 3rd item, when it encounters 2 while runing for i in 1 2 3 4 5 6 do if then #jump to element 3 else echo $i fi done o/p 1 3 4 5 6 (4 Replies)
Discussion started by: sam05121988
4 Replies

10. Shell Programming and Scripting

jump to a section in output

HI I have the following output from an autosys command . Now I would like to investigate further .i.e Start Dependent Job Name Status ... (3 Replies)
Discussion started by: ptappeta
3 Replies
qsig(1B)								PBS								  qsig(1B)

NAME
qsig - signal pbs batch job SYNOPSIS
qsig [-s signal] job_identifier ... DESCRIPTION
The qsig command requests that a signal be sent to executing batch jobs. The signal is sent to the session leader of the job. If the -s option is not specified, `SIGTERM' is sent. The request to signal a batch job will be rejected if: - The user is not authorized to signal the job. - The job is not in the running state. - The requested signal is not supported by the system upon which the job is executing. The qsig command sends a Signal Job batch request to the server which owns the job. OPTIONS
-s signal Declares which signal is sent to the job. The signal argument is either a signal name, e.g. SIGKILL, the signal name without the SIG prefix, e.g. KILL, or a unsigned signal number, e.g. 9. The signal name SIGNULL is allowed; the server will send the signal 0 to the job which will have no effect on the job, but will cause an obituary to be sent if the job is no longer executing. Not all signal names will be recognized by qsig. If it doesn't recognize the signal name, try issuing the signal number instead. Two special signal names, "suspend" and "resume", are used to suspend and resume jobs. Cray systems use the Cray-specific suspend()/resume() calls. On non-Cray system, suspend causes a SIGTSTP to be sent to all processes in job's top task, wait 5 seconds, and then send a SIGSTOP to all processes in all tasks on all nodes in the job. This differs from TORQUE 2.0.0 which did not have the abil- ity to propogate signals to sister nodes. Resume sends a SIGCONT to all processes in all tasks on all nodes. When suspended, a job continues to occupy system resources but is not executing and is not charged for walltime. The job will be listed in the "S" state. Manager or operator privilege is required to suspend or resume a job. Note that interactive jobs may not resume properly because the top-level shell will background the suspended child process. OPERANDS
The qsig command accepts one or more job_identifier operands of the form: sequence_number[.server_name][@server] STANDARD ERROR
The qsig command will write a diagnostic messages to standard error for each error occurrence. EXIT STATUS
Upon successful processing of all the operands presented to the qsig command, the exit status will be a value of zero. If the qsig command fails to process any operand, the command exits with a value greater than zero. SEE ALSO
qsub(1B), pbs_sigjob(3B), pbs_resources_*(7B) where * is system type, and the PBS ERS. Local qsig(1B)
All times are GMT -4. The time now is 03:28 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy