Tag Archives: DEBUG

Cannot correctly connect multi-stage C command pipe (among others) (FYI: a lot of code)

By kowit010

Use and complete the template provided. The entire template must be completed. If you don’t, your post may be deleted!

1. The problem statement, all variables and given/known data:

We are supposed to write a C program that parses a command line, separates it into each command (further separates each command into its argument vectors), and then creates a multi-stage execution pipeline.

Example: “ls -l | grep ^d | wc -l”

The program must also print the results to a LOGFILE of each command created, the PIDs of each command, and the exit status of all commands. Finally, the program needs to wait for each program to execute, kill each command if Cntl-C is hit while the pipeline is executing and start over, or simply end the program if Cntl-C is hit beforehand.

2. Relevant commands, code, scripts, algorithms:

This is the code we have to work with. I apologize for the super-long massive block of code, and any problems with formatting or displaying this properly here, but this is what we must work with, and believe me, no one is more frustrated trying to comprehend this than me, since I am not very good at C programming:

file: piper.c

Code:

/***********************************************************************************************

CSci 4061 Spring 2013
Assignment# 3: Piper program for executing pipe commands

Student name: [hidden for confidentiality], [hidden for confidentiality]
Student ID: [hidden for confidentiality], [hidden for confidentiality]
X500 id: [hidden for confidentiality], [hidden for confidentiality]

Operating system on which you tested your code: Linux
CSELABS machine: [hidden for confidentiality]

GROUP INSTRUCTION: Please make only ONLY one submission when working in a group.

***********************************************************************************************/

#include
#include
#include
#include
#include
#include
#include
#include <errno.h>
#include

#define DEBUG

#define MAX_INPUT_LINE_LENGTH 2048 // Maximum length of the input pipeline command
// such as "ls -l | sort -d +4 | cat "
#define MAX_CMDS_NUM 8 // maximum number of commands in a pipe list
// In the above pipeline we have 3 commands
#define MAX_CMD_LENGTH 256 // A command has no more than 255 characters

volatile int interrupt = 0;//used for handling Cntl-C
FILE *logfp;

int run=1,run2=1;
int prev[2],curr[2];
int num_cmds = 0;
char *cmds[MAX_CMDS_NUM+1];
char *cmds2[MAX_CMDS_NUM+1][256];
int cmd_pids[MAX_CMDS_NUM];
int cmd_status[MAX_CMDS_NUM];
int stat;
int printCount=1,success=0;

/*******************************************************************************/
/* ...read more
Source: FULL ARTICLE at The UNIX and Linux Forums

URGENT:Cannot correctly connect multi-stage C command pipe (among others) (FYI: a lot of code)

By kowit010

Use and complete the template provided. The entire template must be completed. If you don’t, your post may be deleted!

1. The problem statement, all variables and given/known data:

We are supposed to write a C program that parses a command line, separates it into each command (further separates each command into its argument vectors), and then creates a multi-stage execution pipeline.

Example: “ls -l | grep ^d | wc -l”

The program must also print the results to a LOGFILE of each command created, the PIDs of each command, and the exit status of all commands. Finally, the program needs to wait for each program to execute, kill each command if Cntl-C is hit while the pipeline is executing and start over, or simply end the program if Cntl-C is hit beforehand.

2. Relevant commands, code, scripts, algorithms:

This is the code we have to work with. I apologize for the super-long massive block of code, and any problems with formatting or displaying this properly here, but this is what we must work with, and believe me, no one is more frustrated trying to comprehend this than me, since I am not very good at C programming:

file: piper.c

Code:

/***********************************************************************************************

CSci 4061 Spring 2013
Assignment# 3: Piper program for executing pipe commands

Student name: [hidden for confidentiality], [hidden for confidentiality]
Student ID: [hidden for confidentiality], [hidden for confidentiality]
X500 id: [hidden for confidentiality], [hidden for confidentiality]

Operating system on which you tested your code: Linux
CSELABS machine: [hidden for confidentiality]

GROUP INSTRUCTION: Please make only ONLY one submission when working in a group.

***********************************************************************************************/

#include
#include
#include
#include
#include
#include
#include
#include <errno.h>
#include

#define DEBUG

#define MAX_INPUT_LINE_LENGTH 2048 // Maximum length of the input pipeline command
// such as "ls -l | sort -d +4 | cat "
#define MAX_CMDS_NUM 8 // maximum number of commands in a pipe list
// In the above pipeline we have 3 commands
#define MAX_CMD_LENGTH 256 // A command has no more than 255 characters

volatile int interrupt = 0;//used for handling Cntl-C
FILE *logfp;

int run=1,run2=1;
int prev[2],curr[2];
int num_cmds = 0;
char *cmds[MAX_CMDS_NUM+1];
char *cmds2[MAX_CMDS_NUM+1][256];
int cmd_pids[MAX_CMDS_NUM];
int cmd_status[MAX_CMDS_NUM];
int stat;
int printCount=1,success=0;

/*******************************************************************************/
/* ...read more
Source: FULL ARTICLE at The UNIX and Linux Forums

How to grep the grant statement and output to the different files?

By jediwannabe

Hi

currently I have a list of *.sql files.

one of the file, terminal is

Code:

Prompt Table TERMINAL;
CREATE TABLE TERMINAL
(
TERMINAL_ID NUMBER(8),
EXCEL_TERMINAL_ID NUMBER(8),
MERCHANT_ID NUMBER(8),
SETTLE_TIME VARCHAR2(4 CHAR)
);

COMMENT ON TABLE TERMINAL IS 'This tables stores all the terminal details';

COMMENT ON COLUMN TERMINAL.TERMINAL_ID IS 'EXCEL internal unique terminal Identifier. PK for Terminal table';

COMMENT ON COLUMN TERMINAL.EXCEL_TERMINAL_ID IS 'This is ID within a merchant. This number is re-initialized for each merchant';

COMMENT ON COLUMN TERMINAL.MERCHANT_ID IS 'Merchant identifier (References Merchant.merchant_id)';

COMMENT ON COLUMN TERMINAL.SETTLE_TIME IS 'Settlement time of terminal';

Prompt Privs on TABLE TERMINAL TO BONUS_USER to BONUS_PORTAL;
GRANT ALTER, DELETE, INDEX, INSERT, REFERENCES, SELECT, UPDATE, ON COMMIT REFRESH, QUERY REWRITE, DEBUG, FLASHBACK ON TERMINAL TO BONUS_USER;

Prompt Privs on TABLE TERMINAL TO EXCEL_TXN to EXCEL_TXN;
GRANT ALTER, DELETE, INDEX, INSERT, REFERENCES, SELECT, UPDATE ON TERMINAL TO EXCEL_TXN WITH GRANT OPTION;


My output will be to 2 files for one 1 file, terminal.sql
output file 1, terminal_to_bonus_user,sql

Code:


Prompt Privs on TABLE TERMINAL TO BONUS_USER to BONUS_PORTAL;
GRANT ALTER, DELETE, INDEX, INSERT, REFERENCES, SELECT, UPDATE, ON COMMIT REFRESH, QUERY REWRITE, DEBUG, FLASHBACK ON TERMINAL TO BONUS_USER;


My output file 2, terminal_to_excel_txn.sql

Code:

Prompt Privs on TABLE TERMINAL TO EXCEL_TXN to EXCEL_TXN;
GRANT ALTER, DELETE, INDEX, INSERT, REFERENCES, SELECT, UPDATE ON TERMINAL TO EXCEL_TXN WITH GRANT OPTION;


My ksh code, grep_grant_tables.sh is as follow:

Code:

#!/bin/ksh

for i in *.sql
do
if [ -Z `grep EXCEL_TXN "$i"` ]
grep XLS_TXN "$i" > "${i%.*}_to_excel_txn.sql"
fi
grep BONUS_PORTAL "$i" > "${i%.*}_to_bonus_user.sql"
done

exit


when I run my code

Code:

grep_grant_tables.sh: syntax error at line 7: `fi' unexpected


May I know how to resolve the above?

thanks a lot!

…read more
Source: FULL ARTICLE at The UNIX and Linux Forums

Trimming in between the words

By navsan420

Hi i have a log file

Code:

P12345_15728710[01/03/2013 18:16:35]:DEBUG:Begin
P12345_15728710[01/03/2013 18:16:35]:DEBUG:Being
P12345_15729310[01/03/2013 18:48:35]:DEBUG:GetAgen
P12345_15726510[01/03/2013 18:49:35]:DEBUG:end


i want to trim this file and i want like this

Code:

15728710[01/03/2013 18:16:35]
15728710[01/03/2013 18:16:35]
15729310[01/03/2013 18:48:35]
15726510[01/03/2013 18:49:35]


i tried sed

Code:

sed "s/.*P12345__ (.*) :DEBUG*/1/"


Source: FULL ARTICLE at The UNIX and Linux Forums