Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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
share|improve this answer
    
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.