3

I want to have a simple way to enter messages for employees to see upon logging in. It doesn't have to be date specific, although that would be nice, but I can't find a way to use dialog to allow me to enter multiple lines of text before I cat to the file.

Little help?

#!/bin/sh
DIALOG=${DIALOG=dialog}
tempfile=`tempfile 2>/dev/null` || tempfile=/tmp/test$$
trap "rm -f $tempfile" 0 1 2 5 15

$DIALOG --title "Bulletin Board Entry" --clear \
        --inputbox "Enter Today's Very Important\n
employee information below:" 16 51 2> $tempfile

retval=$?

case $retval in
  0)
    echo "Input string is `cat $tempfile`";;
  1)
    echo "Cancel pressed.";;
  255)
    if test -s $tempfile ; then
  cat $tempfile
else
  echo "ESC pressed."
fi
;;
esac
chepner
  • 7,041

3 Answers3

0

a simple way to enter messages for employees to see upon logging in

For the purpose of displaying a file, there's --textbox file height width instead of --editbox filepath height width as suggested. They're also --tailbox file height width and --tailboxbg file height width.

For the purpose of displaying a text (not in a file but from a variable or directly provided quoted), they're --infobox text height width or --msgbox text height width or --yesno text height width, but not --inputbox text height width [init]

I read in a comment that OP was under RHEL5 where some of those widgets are missing but they're alternatives as you can see.

to allow me to enter multiple lines of text before I cat to the file.

Not clear for me: displayed texts or files aren't limited in number of lines. If the purpose is to let users fill the board, I'd go with use of $EDITOR as suggested, because it's more convenient and friendly for the users.

gildux
  • 282
0

Use --editbox emptyfile instead of --inputbox. Unfortunately this won't allow you to pass /dev/null instead of emptyfile, so you'll actually have to create an empty (temporary) file. Or a file containing a message template.

MvG
  • 1,519
0

As an alternative to dialog, you could simply fire up an editor with the temporary file. That way, every user might even be able to use his or her preferred $EDITOR, instead of the feature-limited dialog. Many applications do this kind of thing when they want user input. Version control systems in particular come to my mind here.

MvG
  • 1,519