Calling an interactive perl script from within a while-read loop


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Calling an interactive perl script from within a while-read loop
# 1  
Old 09-27-2013
Calling an interactive perl script from within a while-read loop

Hi,

I have a perl script that prompts for a user to enter a password before doing what it does. This works well if I call it directly from a bash script
Code:
#!/bin/bash
/path/to/perl/script $arg1 $arg2

But, when I try to enclose this within a while read loop, the perl script is called but if I enter an incorrect password, I do not get prompted again and the loop moves on to the next run.

Code:
#!/bin/bash
while read line 
arg1=`echo $line | sed 'something'`
arg2=`echo $line | sed 'something else'`
/path/to/perl/script $arg1 $arg2 < /dev/tty
done < /path/to/file

Any suggestions on how can I fix this problem? I would like to be prompted and allowed to enter the password as many times as the perl script allows me to before moving on.

Thanks!

Last edited by prafulnama; 09-27-2013 at 01:26 PM..
# 2  
Old 09-27-2013
The perl script is reading the password from standard input.

Inside the while loop, standard input is /path/to/file, so it reads the next line, fails the password, and quits the loop after only processing half of the lines.

Do ./perl-script ... < /dev/tty to read the password from the keyboard properly.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Having trouble getting my interactive perl script to work properly

So I'm making an interactive perl script, but I can't get it to work properly. I'm trying to make a script that tell the user to input either 'q' or 'Q' to terminate the program, or 'c' to continue it. If they input anything other than those three keys, it should prompt the user again and again... (5 Replies)
Discussion started by: Eric1
5 Replies

2. Shell Programming and Scripting

Calling a script from a shell that needs to cancel out of infinite loop

I am writing a shell script that calls this oracle utility to get some information about the DB that I need for the script https://docs.oracle.com/cd/B16240_01/doc/em.102/e15294/options.htm This is the command that I am running: $ORACLE_HOME/OPatch/opatch lsinventory -details | grep -i... (1 Reply)
Discussion started by: guessingo
1 Replies

3. Shell Programming and Scripting

Calling perl from shell script

I am calling a perl script from shell script. $ cat mah_appln_bkp_oln.ksh #!/bin/ksh . /udb/home/udbappln/.profile . /udb/home/udbappln/sqllib/db2profile Com=/udb/udbappln/utility/systemscripts/currentUMR perl $Com/backup.pl -d dbname --tsm --purgetsmcopies 21 --purgetsmlogs exit 0 ... (1 Reply)
Discussion started by: ilugopal
1 Replies

4. Shell Programming and Scripting

calling a shell script present on another server using perl script.

Hi, I am working on a sever A. I want to write a perl script to execute a shell script persent on the server B. please help me in this. thanks in advance. (3 Replies)
Discussion started by: anandgodse
3 Replies

5. Shell Programming and Scripting

How we can pass the argument when calling shell script from perl script

Can someone let me know how could I achieve this In one of per script I am calling the shell script but I need to so one thing that is one shell script call I need to pass pne argument.In below code I am calling my ftp script but here I want to pass one argument so how could I do this (e.g:... (5 Replies)
Discussion started by: anuragpgtgerman
5 Replies

6. Shell Programming and Scripting

calling a perl script with arguments from a parent perl script

I am trying to run a perl script which needs input arguments from a parent perl script, but doesn't seem to work. Appreciate your help in this regard. From parent.pl $input1=123; $input2=abc; I tried calling it with system("/usr/bin/perl child.pl $input1 $input2"); and `perl... (1 Reply)
Discussion started by: grajp002
1 Replies

7. Shell Programming and Scripting

Calling a Perl script in a Bash script -Odd Situation

I am creating a startup script for an application. This application's startup script is in bash. It will also need to call a perl script (which I will not be able to modify) for the application environment prior to calling the application. The problem is that this perl script creates a new shell... (5 Replies)
Discussion started by: leepet01
5 Replies

8. Shell Programming and Scripting

Calling 3 perl script from one

hi all, I have 3 perl scripts a.pl,b.pl and c.pl each of these work when i pass a date for eg: perl c.pl 2010-05-27 now i want to write a perl script that would call the 3 scripts and make it run all the 3 scripts (a.pl,b.pl,c.pl) parallelly rather than 1 after the other....... pls... (2 Replies)
Discussion started by: siva_nagarajan
2 Replies

9. 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

10. Shell Programming and Scripting

calling problem in perl script

Hi , Here is my piece of code-- main(); sub main { $result = GetOptions ("LogDir=s" => \$LogDir, "Summary" => \$Summary, "Indiviual=s" => \$Individual , "Diagnostics=s" => \$Diagnostics, ... (1 Reply)
Discussion started by: namishtiwari
1 Replies
Login or Register to Ask a Question