Operating System - HP-UX
1833847 Members
2218 Online
110063 Solutions
New Discussion

Script ignores every other key press

 
SOLVED
Go to solution
Tony Walker
Frequent Advisor

Script ignores every other key press

Hi Guys,

I have written the attached script which enables our user management to team to add/remove/modify entries in a file. I have written a pretty simple menu system which prompts for a menu number and does a 'case' on the response. This works fine and I have tested each module OK. The problem I have is, after adding a user, the terminal seems to ignore every other key press i.e I have to hit Enter twice to continue and if I wanted to enter TONY as the next name I'd have to type TTOONNYY. This only seems to happen after one module has run once, if a stop and start the script - no problem. Any thoughts suggestions would be most appreciated.

Cheers,

Ton
7 REPLIES 7
Dietmar Konermann
Honored Contributor

Re: Script ignores every other key press

Looks like some command is garbling your stty settings. You may save the current settings using

stty -g >tmpfile

Later you can restore them using

stty $(cat tmpfile)

To find the root cause you may compare the stty -a results before and after...

Regards...
Dietmar.
"Logic is the beginning of wisdom; not the end." -- Spock (Star Trek VI: The Undiscovered Country)
Robin Wakefield
Honored Contributor

Re: Script ignores every other key press

Hi Ton,

The line:

awk -F: '{print $1}' $PASSWD|grep -q ^$CHECK /etc/passwd

doesn't look right. Where is PASSWD defined? And the code before the pipe is irrelevant anyway, as you're not doing anything with the output.

Rgds, Robin
Tony Walker
Frequent Advisor

Re: Script ignores every other key press

Dietmar, thanks for that, I'll look into this further and report back. Robin, well spotted, the line should read awk -F: '{print $1}' /etc/passwd|grep -q $CHECK. You'll notice I am using the exit code as input for the variable INPASSWD (hence using grep with -q).
harry d brown jr
Honored Contributor

Re: Script ignores every other key press

Fixing that AWK line Robin pointed out is the KEY to your problem.

PLUS, you need to RETAIN the variable (a line in the WID file)

NEW_USER #

otherwise the next user added gets SQUAT (/dev/null, "", '', nil, ...) for an ID



If ever there was a need to write a program in perl, this is without a doubt one of them!



live free or die
harry
Live Free or Die
Tony Walker
Frequent Advisor

Re: Script ignores every other key press

Harry, the file is maintained in such away that there are numerous lines i.e
NEW_USER 02
NEW_USER 32
NEW_USER A2

The script just replaces the first instance with a username and more are added manually as needed (I'm still trying to get to grips with the ageing policies here).
This does appear to have fixed the problem(!). Can you tell me why??

Thanks

Tony (need to learn Perl)
harry d brown jr
Honored Contributor
Solution

Re: Script ignores every other key press

The GREP was consuming your input until the "buffer" was full. Had you used ctrl-d or just filled up the input with spaces or whatever, then the grep's input would have been satisfied. The awk statement feeding the grep was providing NO input to the grep statement.

Have you thought about doing this in perl?


live free or die
harry
Live Free or Die
Tony Walker
Frequent Advisor

Re: Script ignores every other key press

Wow, every time I think I know a bit more I realise I know a lot less... Thanks for that Harry - makes sense now. My Perl knowledge is basic at best so the thought never crossed my mind. Probably a good project to start learning with though.