Visit Our UNIX and Linux User Community


Making a trace for a script


 
Thread Tools Search this Thread
Operating Systems AIX Making a trace for a script
# 1  
Old 09-07-2016
Wrench Making a trace for a script

Hello experts,

I'm trying to make a trace (unix log) in hope to see why I have differences in some bases :

I putted at the first { and in the last line } > $DATA_SAS 2>&1


Is it a right command ? Do you have another solution ?



thank you,
regards,

Last edited by rbatte1; 09-07-2016 at 06:36 AM.. Reason: Added ICODE tags
# 2  
Old 09-07-2016
how about execute the script with -x option ?
Code:
bash -x script >/tmp/out.txt 2>&1

# 3  
Old 09-07-2016
I tried with set -x but the script is to big, I can't see the whole execution on putty, for this I'm trying with a trace



Thank you for your advice,

Regards,

Last edited by rbatte1; 09-07-2016 at 06:39 AM.. Reason: Added ICODE tags, capitalised first person singular & corrected spelling.
# 4  
Old 09-07-2016
Quote:
.... I have differences in some bases
I'm a little confused as to what this means. Can you post your code (wrapped in CODE tags) then show us the input you have and the expected output & errors you are getting (all wrapped in CODE tags too)

The more you can explain your issue, the more likely we are to be able to help.



Kind regards,
Robin
This User Gave Thanks to rbatte1 For This Post:
# 5  
Old 09-07-2016
Code:
#! /usr/bin/ksh -p


# 0          INPUT PARAMETER
###############################################################

set -x



{


    TMPDIR=/data/work/tmp/PROU
    export TMPDIR

    xYYYYMMDD=$1
    if [ -s ./LOG/history_launch.txt ] ; then
        echo "-----------------------------------------------------------------------------------------------------------------"
        echo "LAST LAUNCH:"
        echo "-----------------------------------------------------------------------------------------------------------------"
        cat ./LOG/history_launch.txt | head -1 
        cat ./LOG/history_launch.txt | tail -1
        echo "-----------------------------------------------------------------------------------------------------------------"
    fi

    if [ ${xYYYYMMDD} -gt 0 ] ; then
        YYYYMMDD=${xYYYYMMDD}
    else
        echo " ENTER OBSERVATION DATE (YYYYMMDD) ? "
        #YYYYMMDD=20160805
        read YYYYMMDD
        echo "-----------------------------------------------------------------------------------------------------------------"
    fi

    # 1          TOOL PARAMETERS
    ###############################################################

    # 1.1        DATES  
    ###############################################################
    DD=`echo ${YYYYMMDD} | extraire -c 7-8`
    MM=`echo ${YYYYMMDD} | extraire -c 5-6`
    YYYY=`echo ${YYYYMMDD} | extraire -c 1-4`
    YYYYMM=${YYYY}${MM}

    # 1.2        LOADING PREDEFINED PARAMETERS
    ###############################################################
    . ./PARAMETERS/parameters

    # 1.3        EXPORT VARIABLES TO SAS
    ###############################################################
    export PROGRAMS=${PROGRAMS}
    export YYYYMMDD=${YYYYMMDD}
    export YYYYMM=${YYYYMM}
    export BASES_DIR=${BASES_DIR}
    export DATA_TMP=${DATA_TMP}
    export DATA_SAS=${DATA_SAS}
    export DATA_TXT=${DATA_TXT}
    export OUTPUTS=${OUTPUTS}
    export SASOUT=${SAS_OUT} 

    # 2          CHECKING MOUCHARD EXISTANCE  
    ###############################################################
    if [ -s ${MOUCHARD}/COMSE.${YYYYMMDD}.Z ] ; then


        # 2.1        MOUCHARD EXISTS
        ###############################################################

        # 2.1.1      CHECKING PHASE 1 FILE(S) EXISTANCE 
        ###############################################################

        if [ -s ${DATA_SAS}/f1_??????_????????.sas7bdat ] ; then

            # 2.1.1.1    PHASE 1 FILE(S) EXISTS
            ###############################################################

            # 2.1.1.1.1  MANAGING PREVIOUS F1 DATE 
            ###############################################################


            cd ${DATA_SAS}
            YYYYMMDDb=`ls -1 f1_??????_????????.sas7bdat | tail -1 | extraire -c 11-18`
            YYYYMMb=`ls -1 f1_??????_????????.sas7bdat | tail -1 | extraire -c 4-9`
            cd ${TOOL_DIR}
            export YYYYMMDDb=${YYYYMMDDb}
            export YYYYMMb=${YYYYMMb}


} > $DATA_SAS 2>&1


Moderator's Comments:
Mod Comment Start using code tags please.

Last edited by zaxxon; 09-07-2016 at 08:44 AM..
# 6  
Old 09-07-2016
There is nothing in your script that assigns a value to the variable DATA_SAS. The command:
Code:
export DATA_SAS=${DATA_SAS}

does absolutely nothing if DATA_SAS is a variable defined in your environment when your script starts (exported variables remain exported). If DATA_SAS is not an environment variable that is exported to your script, that command sets DATA_SAS to an empty string and exports it.

If we assume that the above command is a no-op and that $DATA_SAS expands to a string that is a pathname of a file, then at least one of the following commands in your script:
Code:
cd ${DATA_SAS}
YYYYMMDDb=`ls -1 f1_??????_????????.sas7bdat | tail -1 | extraire -c 11-18`
YYYYMMb=`ls -1 f1_??????_????????.sas7bdat | tail -1 | extraire -c 4-9`
cd ${TOOL_DIR}
export YYYYMMDDb=${YYYYMMDDb}
export YYYYMMb=${YYYYMMb}


} > $DATA_SAS 2>&1

has to fail. You can't change directory to a regular file; only to a directory. And you can't redirect output to a directory; only to a non-directory file.

If $DATA_SAS expands to an empty string, the redirection should fail with a syntax error.

If $DATA_SAS expands to a pathname of a directory, the redirection should fail.

If $DATA_SAS expands to a pathname of an existing regular file to which you have write permission or a non-existent file in a directory in which you have write permission, you should have gotten the output you wanted, but the attempt to change directory would have failed. Otherwise the redirection would have failed.

If we assume that $DATA_SAS does expand to the pathname of a directory, maybe you could get what you want if you change the line in your script:
Code:
} > $DATA_SAS 2>&1

to:
Code:
} > "$DATA_SAS"/logfile_name 2>&1


Last edited by zaxxon; 09-07-2016 at 08:48 AM.. Reason: changed /ICDOE to /ICODE
This User Gave Thanks to Don Cragun For This Post:
# 7  
Old 09-07-2016
After formatting and indenting your script, there also seems to be missing 2 times fi to close the opening if.
Having a glance at your script I wonder if you ever tested any parts of it when writing it or did you just type if down all the way?
This User Gave Thanks to zaxxon For This Post:

Previous Thread | Next Thread
Test Your Knowledge in Computers #120
Difficulty: Easy
The UNIX certification mark is commercially licensed by AT&T.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Help me making this script

This script is executed whenever a new vehicle is added to the cycle-motor park of campus. The script asks for the following information about the car and adds a new line to the vehicle file.txt: name (name of an animal, unique identifier), color, mark, model, type (e.g., electrical, manual),... (2 Replies)
Discussion started by: andre2222
2 Replies

2. UNIX for Beginners Questions & Answers

awk script to find repeated IP adress from trace file (.tr)

+ 8.00747 /NodeList/0/DeviceList/0/$ns3::PointToPointNetDevice/TxQueue/Enqueue ns3::PppHeader (Point-to-Point Protocol: IP (0x0021)) ns3::Ipv4Header (tos 0x0 DSCP Default ECN Not-ECT ttl 63 id 0 protocol 17 offset (bytes) 0 flags length: 540 10.1.3.3 > 10.1.2.4) ns3::UdpHeader (length: 520 49153 >... (11 Replies)
Discussion started by: Nipa
11 Replies

3. Shell Programming and Scripting

Need Help With making this script

Hello, im a new user on this site and learning scripting very slowly at a understanding pace. However i am up with a challenge and require help completing this. The script has to include arguments, variables, decisions and loops. So the script is about calculating the broadcast address for any... (5 Replies)
Discussion started by: tHe666
5 Replies

4. Shell Programming and Scripting

How to put a trace on shell script running in AIX?

Please help me in putting a trace on shell script running in AIX Best regards, Vishal (3 Replies)
Discussion started by: Vishal_dba
3 Replies

5. Shell Programming and Scripting

I could use some help with making a script

I run a small instrument lab. We track our user's time on the instruments with a very manual process of 'last wtmp.1' then cut/paste data into spreadsheets. My boss makes the initial spreadsheets then I convert and format them for uploading into our billing software (COReS). Cores is looking for a... (8 Replies)
Discussion started by: jpontius
8 Replies

6. Solaris

Ping trace telnet monitoring script

Hello, it is my first post :) I need to implement some monitoring tools in a script, ping telnet traceroute I found this one to ping, it works, #!/bin/sh for i in `cat /tmp/PingStatus.txt` do ping -c 5 -w 5 -n $i | grep -q "bytes from" && echo "$i is OK" || opcmsg object=PING a=OS... (5 Replies)
Discussion started by: marmellata
5 Replies

7. Shell Programming and Scripting

Script to report on Oracle's trace files

Hi All, Does anyone have any shell script out there that looks into Oracle trace files generated in the bdump, cdump & udump directories & reports on the contents (errors) within these files. Your help is highly appreciated. Regards, - divroro12 - (5 Replies)
Discussion started by: divroro12
5 Replies

8. Shell Programming and Scripting

making script

hello experts cany any one help me i want to make one script which can rlogin to another machine . but it should not ask me username/password from me of another machine it should take the username and password from the script only. please help me out. regards, shary (2 Replies)
Discussion started by: shary
2 Replies

9. Shell Programming and Scripting

Need help making a script

Here is what I have: #!/bin/bash # Setup year date and month YR=`date +%Y '{print $6}'` MON=`date +%b '{print $2}'` DAY=`date +%d '{print $3}'` file=$YR$MOY$DOM # clear # Dump database using USER/PASS to ..sql mysqldump --user=me -ppass database > database-db.$file.sql The YR, MON and... (2 Replies)
Discussion started by: npereira
2 Replies

10. Shell Programming and Scripting

Script to move trace files

Please debug this shell script for me.. Basically the idea is to run the script, based on the command to move some trace files to a separate directory and I am getting the error. Only the COMMAND that has rm {} works and I basically want to use it for the fourth one. Please try for the 2nd, 3rd and... (4 Replies)
Discussion started by: ST2000
4 Replies

Featured Tech Videos