Can any one please explian me the below bteq code.
Is this script valid?
exec 1> $CODE/edlr2/logs/AGP_MBR_BTEQ_CSA_MBR_STG_LOAD_$(date +"%Y%m%d_%H%M%S").log 2>&1`echo "script file =" $0 PARM_FILE=$1 echo "parm file= "$PARM_FILE.parm . $CODE/edlr2/scripts/$PARM_FILE.parm select name from customer;
Can anyone please explain this code
See: https://superuser.com/questions/436586/why-redirect-output-to-21-and-12
exec 1> $CODE/edlr2/logs/AGP_MBR_BTEQ_CSA_MBR_STG_LOAD_$(date +"%Y%m%d_%H%M%S").log
This writes to a log file
2>&1 `echo "script file =" $0 PARM_FILE=$1 echo "parm file= "$PARM_FILE.parm . $CODE/edlr2/scripts/$PARM_FILE.parm select name from customer;
2>&1 points the file descriptor #2 to where #1 (above) is already pointing (the .log file).
However it looks like you're missing an ending grave ` somewhere above since you start one before echo but never close it. So I don't think that script is valid. But I also know nothing about how your database is setup to evaluate if the rest is valid. Unless you can give specific errors and information about how your files are setup and doing, it's hard to help you.
Additional info: exec will run a script at a location, and so part:
echo "script file =" $0 PARM_FILE=$1 echo "parm file= "$PARM_FILE.parm . $CODE/edlr2/scripts/$PARM_FILE.parm select name from customer;
is essentially running a command script and logging it to a log file. It would output and run something like:
script file=/var/somefile
parm file=/var/someparms.parm
. /var/anotherparmfile.parm select name from customer;
What is exec
What is a dot command
As is, it is neither a unix script, nor some code, nor something bteq could use.
My guess would be, your 'script' looks like this (dismissed the lonely ` as typing error)
exec 1> $CODE/edlr2/logs/AGP_MBR_BTEQ_CSA_MBR_STG_LOAD_$(date +"%Y%m%d_%H%M%S").log 2>&1
echo "script file =" $0
PARM_FILE=$1
echo "parm file= "$PARM_FILE.parm
. $CODE/edlr2/scripts/$PARM_FILE.parm select name from customer;
As #Xander already guessed it would redirect output to a log-file and print info about script and logfile name and then execute the script $PARM_FILE.parm with some parameters.
Further guessing, because BTEQ is mentioned in the name for the log file, in that .parm script bteq may be used to execute a SQL-command which is passed to it as parameters.
bteq needs a logon command. If that is added in the .parm script, before the concatenated parameters, and that passed to bteq, you may get some meaningfull response.
Be aware, that the ; at the end would never be passed to the script. The shell would take it as end of command token. And the .parm script would have to add the ; too to construct a valied SQL-command.
Why a dot-command is used to execute a script, which is named .parm is beyond my imagination.
Related
I need to get different SFTP exit codes for each error. For instance 'no such file or directory' --> exit code=552 or 550 instead of returning 1.
I've tried the following and it did not work:
//A05FTP EXEC PROC=SFTPROC,COND=(0,NE)
//COPSFTP.MYSTDIN DD *
host="xpto.xpty.xptz"
lzopts mode=text
cd /home/apl/files/unl
ls
a=`ls | wc -l`
echo `$a`
echo $?
QUIT
//*
and the output in spool is:
cozsftp> lzopts mode=text
mode=text
cozsftp> lzopts mode=text
mode=text
cozsftp> cd /home/apl/files/unl
Ý09.807¨ Invalid command.
cozsftp> a= 1
CoZBatchÝI¨: returning rc=exitcode=1
Can anyone help me?
COZBATCH allows you to embed shell scripts into JCL, so you don't need to use BPXBATCH. BPXBATCH really is a poor utility. If you're using Co:Z then good for you it rocks.
If you want to run shell commands you need to use the ! escape character.
!echo $a
FWIW, SFTP always returns 1 on error. I'm not sure if you can change that. Errors should be logged in the sysout.
Your problem may simply be the echo `$a`. Try enclosing with quotes instead of tick marks.
More generally, if you want to do more detailed error checking, instead of using the SFTP procedure (SFTPROC), I think you'd do better to write yourself a simple script that you execute with BPXBATCH. The script would issue the same SFTP commands, but you could capture and redirect the output (STDOUT/STDERR) and based on the return value ($?) and any error messages, you could certainly detect all the unusual conditions you might want.
The intended result of this program is to perform the deletion of a record from a temporary file by searching for the last name. If the name is in the file it will display a message that the record is deleted from the file. The message will have a last and first name of the person deleted. If there is no record for the name entered, display an error message indicating that the name is not in the file. The error message will have the last name of the person searched.
For the most part I have figured this code completely out. However, I am running into errors that are giving me a lot of trouble.
Code is as follows:
#While loop
delete_choice="y"
until [[ $delete_choice == "n" ]]
do
#Create Delete Message
clear
echo " Delete Record "
echo -en '\n'
echo -en '\n'
echo "What is the last name of the person you want to delete:"
read last_name
if line=$( grep -Fi "$last_name" "$2")
then
IFS=: read c1 c2 rest <<< "$line"
echo -e "Last Name: $c1\nFirst Name: $c2\nSTUDENT RECORD HAS BEEN DELETED FROM FILE"
sed "/$line/d" $2
else
echo "ERROR: $last_name is not in database"
echo "Would you like to search again (y/n)"
read delete_choice
fi
done
;;
So what happens when I execute this code is it brings up the delete message and asks me to input a last name. I put in a last name "smith", when I do this it skips the whole if statement and goes right to the end of the loop and then brings me right up to asking me what the last name is of the person I want to delete. So obviously it is concentrated in the grep statement somewhere. Another odd thing is if I put a name that I know is not in there it will take me to the else statement and give me the error message and ask me if I want to search again.
Any help would be appreciated, I been searching for hours with the grep statement and cannot figure it out.
Additionally: On a side note does anybody know how to make it so I can input "n" or "N" in the Until...Do statement to keep the loop going?
EDIT:
Ok I fixed all the other problems in this code but there is just one problem I cannot fix. Every time I delete an entry from the file it doesn't allow me to execute the echo command.
Code is as follows:
d|D)
#While loop
delete_choice="y"
while true
do
#Create Delete Message
clear
echo " Delete Record "
echo -en '\n'
echo -en '\n'
echo "What is the last name of the person you want to delete:"
read last_name
if line=$(grep -i "^${last_name}:" "$2")
then
echo "$line" |
while IFS=: read c1 c2 rest; do
last=$c1
first=$c2
sed -i "/^$c1:$c2:/d" "$2"
done
echo -e "Last Name: $last\nFirst Name: $first\nSTUDENT RECORD HAS BEEN DELETED FROM FILE"
else
echo "ERROR: $last_name is not in database"
echo "Would you like to search again (y/n):"
read delete_choice
case $delete_choice in [Nn]) break;; esac
fi
done
;;
As you can see I execute the echo command but it never displays. However, I can tell that it deletes the entry from the file when I exit the program and check it. Does anybody know how to make it display the echo command correctly?
You have used <<< which is a Bash-only feature.
The proper way to debug your problem is to run your script with ksh -x script arg (or possibly sh -x script arg if your script was a pure Bourne shell script; but this one isn't).
However, you have some peculiarities in your code. Allow me to offer a refactoring.
delete_choice="y"
until [[ "$delete_choice" == "n" ]]
do # Indent your control structures
clear
echo " Delete Record"
echo # Massive trailing whitespace removed ----------^^^
echo # Just echo to output a new line
echo "What is the last name of the person you want to delete:"
read last_name
case $last_name in [Nn]) break;; esac # Exit on "n"
if line=$(grep -Fi "$last_name" "$2")
then # Indent your control structures
file=$2
oldIFS=$IFS
IFS=:
set -- "$line" # break input into $1, $2, etc
IFS=$oldIFS
echo -e "Last Name: $1\nFirst Name: $2\nI SCREAM IN UPPER CASE"
sed -i "/^$1:$2:/d" "$file" # note quoting and -i and changed variable
else
echo "ERROR: $last_name is not in database"
echo "Would you like to search again (y/n)"
read delete_choice
fi
done
Another problem here was unrelated to your question. Directly executing the user's input in the regex would be extremely careless -- what if somebody input just a for a last name? The changed code will only delete one user, regardless of how short the input; but perhaps the grep should also be anchored to use a tighter search expression.
There is still a possibility that a peculiar name in the database would not match itself, or match more than itself. For example, I use my second given name, so where my full name is required, I often input my name as "First *Middle Last" with an asterisk next to the name I use, which is the convention where I live; but the string *Middle will not match itself in a regular expression.
Also, without -i, the sed script would simply print a copy of the database to standard output.
The delete_choice variable is not getting updated anywhere within your code so you could change the exterior loop to just while true and handle exiting by breaking out of the loop, like I have done. I didn't change the until on the vague speculation that this might be used in other parts of your code which you aren't showing.
I'm trying to read the content from a aux file, but I can't figure why the command don't work, if I use the string in parameter, that was read from read from file..
Script
file=servers.aux
for server in $(cat $file)
do
echo $server
echo $server
`/usr/IBM/WebSphere/App/profiles/BPM/bin/serverStatus.sh $server -username adm -password adm`
done
Result
BPM.AppTarget.bpm01.0
ServersStatus[7]: ADMU0116I:: not found.
In past, I used something like: put the variable in one array and read the variable from that array, but I think this is possible, what I'm doing wrong?
Thanks in Advance
Tiago
I don't think you need the back-ticks on the last line. You're not trying to run the output of the serverStatus.sh script as a command itself, are you?
I have created a script in GAWK, which produces a log file.
I have a number of conditions throughout the script for error handling, and these errors are output to the log file if triggered. I also have a counter which increments when ever an error is encountered. At the end of the script I have the following:
if (intCounter) {
print "the file contains " intCounter " errors, please see below for details" >> LOG_FILE
} else {
print "no errors, operation successful" >> LOG_FILE
}
This is being printed at the end of my log file, in GAWK is there any way of printing something as the first record in a file if that file already contains text?
Thanks,
Shaw
Here is an example:
cat file
data
some other data
here vi have out pattern
this should work
awk 'FNR==NR {if (/pattern/) f=1;next} f {print "This file has pattern";f=0} 1' file file
This file has pattern
data
some other data
here vi have out pattern
this should work
I have a filewatcher.txt file . i want to include a piece of code in an existing unix script(final) that will ask user for input(Y/N) to check whether the file has been renamed(*filewatcher.txt e.g.SAV_filewatcher.txt or xyz_filewatcher.txt ) or the original name(filewatcher.txt) exists.
If the file watcher has not been renamed the existing code(final) will exit.
I'm not positive I understand what you're looking to do, but here are a few basic scripting tips:
if [ -f "filewatcher.txt" ]; then
echo "file has not been renamed"
fi
echo "Please give me some input"
read var
echo "Your input was $var"