Find the answer to your Linux question:
Results 1 to 3 of 3
Hi, all. I have a script that deletes mysql accounts from mysql.user. The user can either get confirmation per deletion with option -i or not. For example, Code: delete_acct -i ...
  1. #1
    Just Joined!
    Join Date
    Oct 2008
    Posts
    11

    terminal input for confirmation -i option

    Hi, all.

    I have a script that deletes mysql accounts from mysql.user. The user can either get confirmation per deletion with option -i or not. For example,

    Code:
    delete_acct -i ^[abc]
    ... says delete all user ids beginning with "a","b", or "c" and prompt the person at the terminal for each one. But again, -i is optional. Here's my script so far:

    Code:
    while read userid; do
      if [ $flag="-i" ]; then
        print -n "Are you sure that you want to delete" $userid "?"
        read answer < /dev/tty
    
        if $answer="y" then delete $userid
        else exit 1
    
      else
        mysql -BCNnqs --disable-pager -u<username> -p<password> <<EOF
        drop user '$userid'@'localhost';
        quit
    EOF
    
      fi
    done < list_master
    My problem is the inner part (which is similar to my problem in another post). I originally had an inner if statement but I was getting syntax errors. Embedding another if,else,fi was causing problems. I know that I can't use a for loop from my last post. I'm wondering if anyone has any advice on the best way to approach this problem.

    Thanks.

  2. #2
    Just Joined!
    Join Date
    Oct 2008
    Posts
    11

    flow control and nesting


    Since I'm still at the top of the queue, I thought I'd that I'm using Ksh.

    Also, I was thinking...

    What I'm really looking for here is some guidance on flow control and nesting. I learned from a different post that you shouldn't nest for loops. But I'm finding in general that scripting (at least in ksh) is not intuitive. I keep wanting to do stuff like this:



    Code:
    for arg; do
      if func $arg; then
    
        while arg; do
          if $arg="x"
            print "PASS 1: " $arg
          else
            print "PASS 2: " $arg
          fi
        done
    
      else
        print "FAIL: " $arg
      fi
    done

    And it keeps failing. I get errors like "syntax error: `else' unexpected". If anyone knows how to explain this concept simply or can point me to a good reference on this specific topic, I would appreciate it.


    Thanks.

  3. #3
    Linux Newbie
    Join Date
    Jul 2008
    Posts
    181
    Have you tried reading the ksh manpage? The one I have is quite clear on the syntax of loops and branches.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...