How to send data to previous program (pipe)?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to send data to previous program (pipe)?
# 15  
Old 02-14-2018
Quote:
Originally Posted by Corona688
Code:
#!/bin/bash

exec 1>&3 # Save stdout into FD 3 if we need it
mkfifo /tmp/$$

echo "fifo is /tmp/$$"
#...

I have an error:
Quote:
$ ./test.sh
./test.sh: line 3: 3: Bad file descriptor
fifo is /tmp/28226
---------- Post updated at 03:52 PM ---------- Previous update was at 03:12 PM ----------

Hello, Don Cragun.
Your "example of using the presence of a file to act as a semaphore..." is ok. However, I need to interact with sqlplus in a normal way (from its inner prompt) also => interactively.
Do you have any idea how may I start sqlplus to instruct it to read an input from some file when the file is not empty and allow the user to do normal commands from prompt like below?
Code:
SQL*Plus: Release 11.2.0.4.0 Production on Wed Feb 14 13:45:42 2018

Copyright (c) 1982, 2013, Oracle.  All rights reserved.

Connected to an idle instance.
SQL>

In your example we can create cmd1 exactly as we wish it to behave. This is not the case when sqlplus is put instead of cmd1.
# 16  
Old 02-14-2018
Oracle's utl_file package allows file i/o. You have to use PL/SQL as part of your script. Note that the DBA has to grant access to the directory by creating a directory object for you - this is part of Oracle security. In older Oracle systems (Oracle 9) there usually is a default object called TMP which usually points to the /tmp directory.
# 17  
Old 02-14-2018
I've been away from this thread for a while.

Would it be possible to have this sort of command still cmd1 | cmd2 but have the sqlplus in cmd2? The cmd1 would need to be reading a file or pipe that cmd2 writes to.

An alternative might be something like cmd1 < <(cmd2) and this time the sqlplus is in cmd1. This is a bash way rather than ksh.

Can you tell us more about the output that the sqlplus will create and how/why it must then take in new input depending what it throws out? It might be better to set it up as a set of separate calls, i.e.
  • script calls sqlplus call to generate some output into work-file1 and then exit
  • script reads work-file1 and calls sqlplus with appropriate input, writing work-file2
  • script reads work-file2 and calls sqlplus with appropriate input, writing work-file3
.... and so on until you have the desired output.

Does anyone care to shoot me down to say that these are all bad approaches? I'd be happy to illustrate how not to do it if that's useful to the thread.


I'm just a bit lost about why the sqlplus needs to have input based on it's output. Have I missed the point?


Robin
# 18  
Old 02-14-2018
Quote:
Originally Posted by JackK
I have an error:
I apologize, that should have been:
Code:
exec 3<&1

# 19  
Old 03-15-2018
Both examples given by Don Cragun and Corona688 are working for me and I understand the idea behind it.
However, both those examples rely on a possibility of creating cmd1 and cmd2 from scratch, so that stdin/stdout redirection (Corona688's example) and testing file existence (Don Cragun's example) can be made.
This is, however, not possible when I have sqlplus instead of cmd1. Am I right? If yes, then my problem is still unsolved.
# 20  
Old 03-15-2018
Quote:
Originally Posted by JackK
Both examples given by Don Cragun and Corona688 are working for me and I understand the idea behind it.
However, both those examples rely on a possibility of creating cmd1 and cmd2 from scratch, so that stdin/stdout redirection (Corona688's example) and testing file existence (Don Cragun's example) can be made.
This is, however, not possible when I have sqlplus instead of cmd1. Am I right? If yes, then my problem is still unsolved.
You have said that in your case, cmd1 is an interactive sqlplus script that you control. You can make that sqlplus script recognize that something in its environment has changed and use recognition of that change to do whatever it is that you want to do. If, on the other hand, your cmd1 is not an interactive sqlplus script or if you can't make that script recognize that something has changed in the outside world and make adjustments based on that change, then you can't do what you say you want to do and there is nothing we can do to help you make that happen (other than things we have already suggested that you have said you don't want to use).
# 21  
Old 03-16-2018
cmd1 in my case is sqlplus (an executable program made by Oracle Corporation) used to connect to database. I have no control at all on this tool so... I am not able to change its behavior.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

RWSocket::send: Broken pipe Error in /var/adm/messages

Hi Guys, I am getting some strange error in /var/adm/messages in my Solaris 10 box with Veritas Cluster and EMC storage. bash-3.00$ cat /var/adm/messages | egrep -v "lw8|snmp|sshd|xntpd|kern.info|LOGIN|link|service|started|finished|repeated|SS7 Log-daemon|success" Dec 18 09:58:35 GAMMa2... (1 Reply)
Discussion started by: vivek.goel.piet
1 Replies

2. Shell Programming and Scripting

Perl to send previous and current value

For example, I have a file called number.txt. x y 1 1 2 4 3 9 4 6 5 5 6 6 7 9 8 4 9 1 10 0 ... And I want to print out the value of x and y, if y%4==0 and the next value of y%4==0. Thus, the sample output is: 1 1 *because the previous x before 2 is 1 2 4 *because 4%4 == 0 7 9... (2 Replies)
Discussion started by: Tzeronone
2 Replies

3. Linux

Perl program to print previous set of lines once a pattern is matched

Hi all, I have a text data file. My aim here is to find line called *FIELD* AV for every record and print lines after that till *FIELD* RF. But here I want first 3 to four lines for very record as well. FIELD AV is some where in between for very record. SO I am not sure how to retrieve lines in... (2 Replies)
Discussion started by: kaav06
2 Replies

4. UNIX for Advanced & Expert Users

sftp error:- Couldn't send packet: Broken pipe

Hi, I am trying to sftp a large file(appx. 2 GB size) from solaris 10 to a Linux server. While sftping(with no options), connection is terminated after some time with broken pipe error. sftp with option -R1 or -B1500 is successful. Linux server ssh Version: OpenSSH_3.9p1, OpenSSL 0.9.7a... (3 Replies)
Discussion started by: brij123
3 Replies

5. Homework & Coursework Questions

pipe program in C

Hello guys, my professor give me 2 days to study and make a program usign pipe, fork in c i need to do a program read a arq.txt the father process read the file and the child print ! 2. Relevant commands, code, scripts, algorithms: like this Code: #include <stdio.h>... (1 Reply)
Discussion started by: beandj
1 Replies

6. Programming

pipe program in C

Hello guys, my professor give me 2 days to study and make a program usign pipe, fork in c i need to do a program read a arq.txt the father process read the file and the child print ! like this #include <stdio.h> #include <stdlib.h> #include <sys/wait.h> int main (){ ... (1 Reply)
Discussion started by: beandj
1 Replies

7. Solaris

sendmail pipe to a program.

Hello, I recently upgraded our server from Solaris 8 to 9. The sendmail is unabled to pipe the email to a perl script. I can send and received email to local and external mail, but the script did not get the email. There is no error in the log and I could not find any thing on the web. Here... (0 Replies)
Discussion started by: ld98
0 Replies

8. Shell Programming and Scripting

Writing a program to receive the GPS data and send to other server

Hi, I would like to write a program to receive the GPS data and then send the data via network to other program. All of the program is not write yet(include host and sender) All of the server OS is unix or linux Could you mind to give me some idea to do this? Thanks so much! Ken ... (2 Replies)
Discussion started by: kenlok
2 Replies

9. UNIX for Dummies Questions & Answers

Script to open program and send/execute command in program

Hi, i want to write a script that executes a program (exec?) . this program then requires a filename as input. how do i give it this input in the script so the program will be complete run and close by the script. e.g. exec prog.exe program then asks for filename "enter filename:"... (1 Reply)
Discussion started by: tuathan
1 Replies

10. Programming

C++ How to use pipe() & fork() with stdin and stdout to another program

Hi, Program A: uses pipe() I am able to read the stdout of PROGAM B (stdout got through system() command) into PROGRAM A using: * child -> dup2(fd, STDOUT_FILENO); -> execl("/path/PROGRAM B", "PROGRAM B", NULL); * parent -> char line; -> read(fd, line, 100); Question:... (2 Replies)
Discussion started by: vvaidyan
2 Replies
Login or Register to Ask a Question