2

I am creating a menu to append or overwrite ssh keys for multiple users using dialog --checklist. The menu is something like this

    0) append
    1) user1
    2) root

What I would like to happen is if option zero is selected and either option 1 or 2 or both are selected it would append rather than over writing the ssh keys when it regenerates.

I'm new to dialog and can't seem to come up with the logic needed to cause this to happen.

My first thought was to use the --separate-output option and somehow use grep on the results but there has to be a more elegant solution. Any help or advise is appreciated.

ss0
  • 33
  • 3

1 Answers1

1

Run dialog like this:

dialog --checklist text 50 20 10 0 append 0 1 user1 0 2 root 0 2> checklist.txt

The 2> pipes stderr to its own file - which is where --checklist's output ends up.

Then read the conents of checklist.txt like this:

APPEND=0
for a in $(cat checklist.txt); do
    if [ "$a" = "\"0\"" ]; then
        APPEND=1
        continue
    fi

    if [ "$APPEND" -eq 0 ]; then
        # Copy ssh key, without appending
    else
        # Append ssh key
    fi
done
Kvisle
  • 4,113
  • 23
  • 25
  • Thanks so much seeing it after you wrote it, it seems so logical! I wouldn't have thought of using a place holder variable like that. I wish I had the rep to upvote your answer! – ss0 Oct 31 '11 at 19:10