Help with bash script

Cameron Simpson cs at zip.com.au
Fri Mar 13 22:12:39 UTC 2009


On 13Mar2009 14:22, Dave Martini <martini1 at llnl.gov> wrote:
| I am writing a bash script to run the nisclient command on a word list with
| a for in loop. I'm using a  here document to accept user
| input in this case I want it to be the letter y so that the script  
| continues.

But your here document contains the text of an echo command, not a "y".
What are you thinking here?

| When I run the script you'll see below it just asks
| over and over if you want to continue y or n. I want the script
| to enter y and continue.

Sounds like nisclient was coded badly and doesn't recognise end-of-file.

| Here is the script I have so far

1: Please indent your code. Unindented code is harder to read and an
   affront to others trying to read it.

| bash-2.03# more change_nis_cred.sh
| #This script script cycles through a word list and uses a for in loop.
| set -x
| #
| for user in credlist.txt

Well, this doesn't "cycles through a word list", presumably from a file
called "credlist.txt". Instead, it cycles through a wordlist whose
entire content is the single word "credlist.txt".

You want to go:

  while read user
  do
    ...
  done <credlist.txt

instead.

| # Start of Here document
| #
| nisclient -cl newpass $user <<- FINIS
| echo "Changed $user account password"
|         FINIS

If you want to enter a 'y' into nisclient, then you probably want to do
this:

  if echo y | nisclient -cl newpass $user
  then
    echo "Changed $user account password"
  fi

I don't understand why you want a here document at all n this case.

| This is what happens when I run the script
| # ./change_nis_cred.sh
| ++ nisclient -cl newpass credlist.txt

This output itself should tell you you are invoking nisclient
incorrectly, with $user being "credlist.txt". Did you read it?

| You will be adding DES credentials in domain daveo.gov. for
| credlist.txt
| ** nisclient will not overwrite any existing entries in the
| ** credential table.
| Do you want to continue? (type 'y' to continue, 'n' to exit this script)  
| Do you want to continue? (type 'y' to continue, 'n' to exit this script)  
| Do you want to continue? (type 'y' to continue, 'n' to exit this script)  
| Do you want to continue? (type 'y' to continue, 'n' to exit this script)  
[...]

This is nisclient being stupid. It legitimately rejects the text:
  echo "Changed credlist.txt account password"
as neither "y" nor "n" and asks again, but then doesn't recognise end of
input as such, and asks again forever.

I'd also consult the manual entry for nisclient and see if it has a
command line option to mean 'y', avoiding the question.

Cheers,
-- 
Cameron Simpson <cs at zip.com.au> DoD#743
http://www.cskk.ezoshosting.com/cs/

C'mon. Take the plunge. By the time you go through rehab the first time,
you'll be surrounded by the most interesting people, and if it takes years
off of your life, don't sweat it. They'll be the last ones anyway.
        - Vinnie Jordan, alt.peeves




More information about the redhat-list mailing list