Hi, can some one help in selecting option in script


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Hi, can some one help in selecting option in script
# 1  
Old 01-02-2011
Hi, can some one help in selecting option in script

Hi,
Some one help in completing the script:

I need to write a script which has to select automatically only one option(below case only D - ALL) out of all options instead of manual entry

There is an script which is used to test number of connection to different db that it connects when we run the script o/p will be like below:
-----
./testconnectiontoDB

Options:
A DB
B DB
C DB
D ALL
Select option:
(Here I have to give an option while executing)

--
Now I need to write a script which will automatically give input as D instead of manually(read) entry, so can some one help me in writting a script which will automatically insert option D and execute the script

Above "testconnectiontoDB" I dont have access to modify the script itself, so I have to execute an different script which will inturn call "testconnectiontoDB" script and followed by option "D" inside the script (instead of manual read option) to copy ALL db connection statistic to output file.

Script should be as below:
-------------------------
cat AllDBStatistics
#..
cd path
./testconnectiontoDB
...
followed by input condition to above read script as D option
..


After executing the above script, I will be copying to some temp file as below:
AllDBStatistics >> Output.file

So can some one assist on above logic.

Thanks/-
# 2  
Old 01-02-2011
If you only need to select "D" once:
Code:
echo D | ./testconnectiontoDB

# 3  
Old 01-04-2011
Thanks can you help in below

Thanks for the update

Can you please also let me know how to copy the output to some temperorify file because // echo D | ./Script > Output // is not working, can you tell the alternate option to copy the complete output of the script which is executed by above.
So that statistics I can send mail to destination user in case of issues by setting some conditions.

Thanks/-
# 4  
Old 01-04-2011
Off the top of my head:
Code:
NAME=$(basename ${0})

LOGDIR=/tmp
FILE=${LOGDIR}/${NAME}.$(date +%Y%m%d%H%M%S)

# remove comment to remove older log files
# find "${LOGDIR}" -maxdepth 1 -type f -name "${NAME}.*" -mtime +14 -exec rm -f {} \;

echo D | scriptdir/testconnectiontoDB > "${FILE}"

# 5  
Old 01-07-2011
Thanks for your assistence

Thanks m.d.ludwig for given Idea:

What is the exact different between both:
1C) echo D | ./testconnectiontoDB
2C) ./testconnectiontoDB | echo D

As per my knowledge by using (1C) D option will be taken and it will get posted to the script it is running right as part of execution? (If I am wrong correct me ..)

In Second option (2C) .. why it wont work in the sameway ..

Please help me inunderstanding the exact difference between both ..

Thanks/-
# 6  
Old 01-08-2011
hello I cant tell apart ,but I think you can get help by the following way:
info "|"
also , you can deeply about the use of "|"
# 7  
Old 01-08-2011
IMHO, understandong [icode]|[\icode] (aka, the "pipe") is fundamental for using UNIX. As is understanding standard-input and -output.

While this is a bit of a simplification, commandA | commandB is functionally equivalent to commandA > tempfile; commandB < tempfile; rm tempfile, but without the overhead of creating, reading, writing, and removing tempfile. Also, both commands are run simultaneously.

So for:
Quote:
Originally Posted by PAKumar
What is the exact different between both:
1C) echo D | ./testconnectiontoDB
2C) ./testconnectiontoDB | echo D
You are correct in:
Quote:
Originally Posted by PAKumar
As per my knowledge by using (1C) D option will be taken and it will get posted to the script it is running right as part of execution? (If I am wrong correct me ..)
Although I would say: D\n (the character "D" followed by a newline character) is written to stdout of echo, which is read by testconnectDB.
Quote:
Originally Posted by PAKumar
In Second option (2C) .. why it wont work in the sameway ..
As per the echo manual page, only output is sent to stdout, nothing is ever read in. So what ever was generated by ./testconnectiontoDB was lost.

Hope this helps.

-- MDL
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with shell script: selecting rows that have the same values in two columns

Hello, everyone I am beginner for shell programming. I want to print all lines that have the same values in first two columns data: a b 1 2 a a 3 4 b b 5 6 a b 4 6 what I expected is : a a 3 4 b b 5 6 but I searched for one hour in... (2 Replies)
Discussion started by: nengcheng
2 Replies

2. Shell Programming and Scripting

Selecting/using part of directory names in script

I'm making a shell script to: -copy directories to a new location -perform conversions on the files within the copied directories -move the newly created files to a new directory Please see my super basic script and notes below... and thank you thank you thank you in advance !! ... (1 Reply)
Discussion started by: kayzee
1 Replies

3. Shell Programming and Scripting

FTP in shell script and selecting files for upload

Hi, Im a newbie with programming and shell scripting. Im running OSX/Mac and Darwin. I would like to create a shell script that would : 1. Search a Volume and directory (including subdirectories) for a file that : * filename ends with ”_Highres.pdf” and * the file creation date of... (8 Replies)
Discussion started by: NickeZ28
8 Replies

4. Shell Programming and Scripting

Script to call a menu script and redirect each option to a text file

Hello, I want to design a script that will call an existing menu script and select options one by one and redirict the out put to a file. For example;- In the script MENU.sh there are 10 options i want to design a script MENU2.sh that will select option 2 3 4 6 7 10 and redirict the output... (4 Replies)
Discussion started by: spradha
4 Replies

5. UNIX for Dummies Questions & Answers

HELP Script don't work selecting lowest value!!!

Hy again guys, Last week i resolve a question here but now i need your help again :rolleyes: I have about 3000 files that i need to choose based on the lowest value, so i make temp files like this: The files can have lines from 1-10 but only 2 columns, the point is to grep the name os the... (2 Replies)
Discussion started by: MetaBolic0
2 Replies

6. Shell Programming and Scripting

perl script command line option driven script

could someone show me a sample command line option driven script? i want to see an easy way to write one and how i can execute it using command line options such as typing in read.pl -i <id> -c <cmds> -s <start> -e <end> would read out all the commands run by ID . from start time to... (7 Replies)
Discussion started by: kpddong
7 Replies

7. Shell Programming and Scripting

recently introduced to the newer option for find...does an older option exist?

To find all the files in your home directory that have been edited in some way since the last tar file, use this command: find . -newer backup.tar.gz Is anyone familiar with an older solution? looking to identify files older then 15mins across several directories. thanks, manny (2 Replies)
Discussion started by: mr_manny
2 Replies

8. Shell Programming and Scripting

bash script for selecting grib files with cdo

hi, i am new with scripts and have a little problem. i have a file with dates in the form YYYYMMDD, in average about 40 days per year. now i shall cut those days with cdo selday from monthly files. the script shall look up the days, forward them to the cdo operator and write the new grib... (1 Reply)
Discussion started by: jumkae
1 Replies

9. UNIX for Dummies Questions & Answers

command for selecting specific lines from a script

I need help on following script: I need to print the lines which are in bold letters in separate file as record string("|") emp_name; string("|") emp_id; decimal("|") emp_salary; string("|") emp_status; string("\n") emp_proj; end (1 Reply)
Discussion started by: gardasgangadhar
1 Replies

10. Shell Programming and Scripting

Urgent: selecting unique specific content of a file using shell script

Hi, I have a file whose content and format at places is as given below. print coloumn .... coloumn .... coloumn .... skip 1 line print coloumn ... skip 1 line I need to select the following : print coloumn .... coloumn .... coloumn... (2 Replies)
Discussion started by: jisha
2 Replies
Login or Register to Ask a Question