Passing answers to external program from KSH


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Passing answers to external program from KSH
# 1  
Old 02-08-2011
Passing answers to external program from KSH

I have asked this before but I haven't had any luck so far getting this to work. I use RCS(revision control system). When it runs if I pass the value 'unlock' to $3 its reassigned to $unlock. When I run the command (rcs -u'version number' 'filename') ti will ask me 1-(Do you want to break the lock y/n?) then 2-(The reason for breaking the lock) 3-(Enter a '.' period on a blank line when done) All I want to pass to the program is (y,production install,'.') When I run rcs manually and I simply hit enter on the line asking if I want to unlock the file, it will terminates and says the file is still locked which is what is occurring. It will not pass the answers I have put into the script. It seems to act like I simply hitting the enter key. Does anyone have any ideas?
Code:
if [[ $unlock = "unlock" ]]; then
print $PS1 "rcs -u${Reqvers} $Reqfile"
rcs -u${Reqvers} $Reqfile<<PAUL
y
PROD install of $acr
PAUL
 fi


Last edited by Franklin52; 02-09-2011 at 03:17 AM.. Reason: code tags
# 2  
Old 02-08-2011
try with expect
# 3  
Old 02-08-2011
I would if I could but the script is doing other things not compatible with expect and this part of the script runs within a while ..do.. done
# 4  
Old 02-08-2011
A ksh co-process might work. Here is an example of using a co-process to talk with the ftp program. But a script that breaks rcs locks automatically would scare me. Smilie
This User Gave Thanks to Perderabo For This Post:
# 5  
Old 02-08-2011
I can see no reason to run this in a while loop.

Why not just have a script with the program name as a parameter "su" to the user holding the lock.
Code:
rcs -u "${program_name}"
Or if it is not the most recent version which is locked:
rcs -u "${revision}" "${program_name}"

For those who are wondering, you need an "unlock" script for the cases when programmers check out a program using "co" with some intention to make changes ... and then make no changes.

As administrator (i.e. root) I always run an unlock script while in a "su" session as the user holding the lock. This way the unlock program does not ask questions.
This User Gave Thanks to methyl For This Post:
# 6  
Old 02-09-2011
Thanks for your responses.

methyl,
There is actually a reason we do it this way and it involves sox compliance rules and auditor requirements. We have generic users setup for testing and production installs and they are the only users allowed to do these installs(actually we su to them) and as such they must be the ones checking out and breaking the locks. The developers cannot be the users doing installs or even be shown as the owners of the files when they are installed(segregation of duties). We normally use HP'S GCM tool to do our installs and it su's to the proper user prior to checking out and installing(and it handles unlocking properly) but sometimes a manual install by my release op's department is required since automation may not be possible for whatever reason. Also this script is only used when we have a large number of files to install and checking them out manually and breaking the lock is time consuming. We also want to be prompted to break the lock since this sends an email to the developer and business owner that the lock is broken and now they can make changes to the code for future installs. It also creates an audit trail. I know this is wordy but we only run this script during production installs by running it with 'unlock' as the third parameter and its at this point we break that lock and we need to be prompted for this so we can enter information about the install ID # and version of the lock being broken, again only for auditing purposes. Its in a loop because we have an input file with several files to process and it needs to loop through each of them. Yeah, this probably just makes it more confusing. I am thinking of just sending the output to a file with file,version and unlock reason and running this separate after all files have been checked out. Maybe using 'expect' as someone suggested but I am unfamiliar with that but it seems fairly straightforward.

---------- Post updated at 08:52 PM ---------- Previous update was at 08:31 PM ----------

Thanks Perderabo,

I'll take a look at that tomorrow. Just getting back into unix/linux and scripting after being stuck in a windows world for so long is taking time to get ramped up again..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Duplicate check by passing external parameter

I have a code which is using to find duplicates in a files based on column.Below is the same code which is used to find duplicates in my file based on column 1 awk -F'|' '{if (x) { x_count++; print $0; if (x_count == 1) { print x } } x = $0}' FileName >Dup_File.txt But my requirement here is... (3 Replies)
Discussion started by: ginrkf
3 Replies

2. Shell Programming and Scripting

Passing external variable to awk

Hi, I am trying to write a bash script in which I need to pass a external variable to the awk program. I tired using -v but it not accepting the value. Here is my sample code. #!/usr/bin/bash ###################################################################################### ####... (5 Replies)
Discussion started by: jpkumar10
5 Replies

3. Shell Programming and Scripting

Problem in passing date to external function from perl script.

my $sysdate = strftime('%Y-%m-%d', localtime ); biDeriveByDate('Table_Str',$sysdate,\@lIndx,\@lResVals) In a perl script, when I'm trying to pass $sysdate to some external function it's not working since $sysdate is passed as a string mentioned above but my function is expecting a date value... (1 Reply)
Discussion started by: Devesh5683
1 Replies

4. Shell Programming and Scripting

passing file extension using external variable

Hi, How can I modify the FILETYPE command ? I want to provide the file extension, like txt, root .? Thanks, #!/bin/bash FROM=$1 TO=$2 FILETYPE=$3 ... (4 Replies)
Discussion started by: nrjrasaxena
4 Replies

5. Shell Programming and Scripting

For loop to run external program

Hi, I was hoping for help with a for loop to run a program (vina) repeatedly using all the files in a folder as input. Currently my code looks like this: #!/bin/bash FILES=/home/afalk/Desktop/battest/*.pdbqt for f in $FILES do vina --config /home/afalk/Desktop/A.txt --ligand "$f".pdbqt done... (5 Replies)
Discussion started by: oldmanwinter
5 Replies

6. Shell Programming and Scripting

passing arguments to external script

Hi! I have a python script that requires arguments and these arguments are file paths. This script works fine when executed like this: /my_python_script "file_path1" "file_path2" (i added quotes as some file names may have weird characters) the issue happens when i launch my python script... (14 Replies)
Discussion started by: gigagigosu
14 Replies

7. Programming

Run external program in background

Hi, in my program i need to run an external program in background.I am aware that there are at least 2 alternatives for this: 1)fork+exec 2)system("program &"); I have read several posts about this,and they all tend to suggest to use fork+exec (and that's what i am doing now). I have some... (2 Replies)
Discussion started by: Zipi
2 Replies

8. Programming

Problem with external program launch

Hello, in the application i'm writing i need to launch "recordmydesktop" to capture the screen,but i'm having a problem: when the recording stops,and the encoding of the saved file starts,the entire system hangs until the completion of the encoding.This happens if i launch recordmydesktop from my... (7 Replies)
Discussion started by: Zipi
7 Replies

9. Shell Programming and Scripting

Passing value to an external program problem...

This code is in my 'case' statement and it all else works fine. The problem I have is that the value in 'procno' is not passed on to the external program (fireit). It is passing all zeros instead of the actual process number. By the time I get to this case statement, I know the "Number" and... (1 Reply)
Discussion started by: giannicello
1 Replies
Login or Register to Ask a Question