Redirecting/Capturing inputs supplied in interactive script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Redirecting/Capturing inputs supplied in interactive script
# 1  
Old 07-11-2013
Redirecting/Capturing inputs supplied in interactive script

Hello

Is it possible to redirect standard input into a file in an interactive script like we do for standard out and input using &2 and &1.

Enter source :
hi
Enter destination :
bye


In the log i can see like this when I am using
Code:
script.sh 2>&1 | tee file

Enter source :
Enter destination :


As of now I am using echo to log the user inputs.
# 2  
Old 07-11-2013
you have to use the named pipes for this..

Code:
 
mkfifo out.pipe err.pipe
exec 3>&1 4>&1
tee Menu_`date +"%d-%m-%Y"`.log < out.pipe >&3 &
pid_out=$!
exec  1>out.pipe
tee Menu_`date +"%d-%m-%Y"`.err < err.pipe >&4 &
pid_err=$!
exec  2> err.pipe
rm out.pipe err.pipe
 
# your interactive script comes here
 
exec 1>&3 3>&- 2>&4 4>&-
wait $pid_out
wait $pid_err

This User Gave Thanks to vidyadhar85 For This Post:
# 3  
Old 07-11-2013
Thanks . But looks complicated for for my level of knowledge.
# 4  
Old 07-11-2013
Quote:
Originally Posted by ningy
Thanks . But looks complicated for for my level of knowledge.
Unfortunately there is no easy way Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script inputs to python

Hi I am trying to pass 2 input parameters from shell script to python API end point ,but not passing what i expected when print those inputs .Please advise data.txt " 7554317" ,xx5e1 " 7554317" ,xx96 " 7554317" ,xxd6 " 554317" ,xde cat $sites/data.txt |sort |uniq >$sites/a.txt... (5 Replies)
Discussion started by: akil
5 Replies

2. Shell Programming and Scripting

Script to cp files that user inputs

Need a bash script that will ask the user: Which Files Would you like to copy? Then the user would input the filenames (space seperated, all lowercase) The script would then cp each file to /data/backup/ and also wc the files to std output. (to see how many lines each file has) Should go... (5 Replies)
Discussion started by: ajp7701
5 Replies

3. Shell Programming and Scripting

Perl script for taking inputs from one script and storing them into a document.

Hi. I wanted to create a Perl script which can take the outputs of a Perl script as it's input and temporarily store them in a document. Need help. Thanks.:) (8 Replies)
Discussion started by: xtatic
8 Replies

4. Shell Programming and Scripting

Need inputs on UNIX script basics

Hi UNIX Gurus, I have a SQL utility which fires DML statements against DB2 tables. Logic is to identify DML statements, put it into a file ($dml) and execute the job. DML file can have more than 1 DML statements....but all of 1 type at a time.....either all UPDATE or all DELETE. Job first... (2 Replies)
Discussion started by: ustechie
2 Replies

5. Shell Programming and Scripting

Newbie Question: Killing a process using a supplied name to a shell script

Hi, I am trying to automate the killing of named processes of which I found a good solution here on the forums but as I am pretty much a begginer to linux I am having an issue. The code I found is: kill $(ps -ef | nawk '/monitoreo start/ { print $2}'} but what I want to do is replace... (3 Replies)
Discussion started by: TylrRssl1
3 Replies

6. Homework & Coursework Questions

How to write script that behaves both in interactive and non interactive mode

Q. Write a script that behaves both in interactive and non interactive mode. When no arguments are supplied it picks up each C program from the directory and prints first 10 lines. It then prompts for deletion of the file. If user supplies arguments with the script , then it works on those files... (8 Replies)
Discussion started by: rits
8 Replies

7. Homework & Coursework Questions

Help with Interactive / Non Interactive Shell script

Q. Write a script that behaves both in interactive and non interactive mode. When no arguments are supplied it picks up each C program from the directory and prints first 10 lines. It then prompts for deletion of the file. If user supplies arguments with the script , then it works on those files... (1 Reply)
Discussion started by: rits
1 Replies

8. Shell Programming and Scripting

need inputs on how i can change my script to reduce amount of time the script takes

HI , I have a list1 which consists of data that i have to search and a list2 which has the files that need to be searched .So basically i am using list1 on list2 to see if list1 data is present if found replace it .I have written the code using foreach loop for each list .This is taking the... (1 Reply)
Discussion started by: madhul2002
1 Replies

9. Shell Programming and Scripting

use several inputs as arguments in my script

Hi there, It's pretty hard for me to explain my problem because I'm affraid I'm not using the correct vocabulary. So let me describe the situation. I wrote a script that has one argument. It works like this: ~$ cat /usr/local/bin/squote echo "$@" | sed 's/'\''/'\''\\'\'\''/g; s/.*/'\''&'\''/g'... (2 Replies)
Discussion started by: chebarbudo
2 Replies

10. Shell Programming and Scripting

redirecting serial inputs to a file?

i have an external device sending serial messages i want to connect this device to a serial port in my sun blade box and record those messages to a file, how can i read the serial port and write it to file? Thanks (4 Replies)
Discussion started by: guilartec
4 Replies
Login or Register to Ask a Question