Page 2 of 2 FirstFirst 12
Results 11 to 20 of 20

Thread: Run a bash script on Terminal Startup

  1. #11
    Join Date
    Apr 2013
    Beans
    10

    Re: Run a bash script on Terminal Startup

    Quote Originally Posted by DrGroove View Post
    Just replace your original line:

    with


    Output when entering the password will be empty.
    Well yeah but I asked how to hide input with *

  2. #12
    Join Date
    Feb 2013
    Beans
    Hidden!

    Re: Run a bash script on Terminal Startup

    Quote Originally Posted by thecodejunkie View Post
    Well yeah but I asked how to hide input with *
    Code:
    exec 3>&1
    passwd=`whiptail --passwordbox 'Enter password:' 7 21 2>&1 1>&3`
    exec 3>&-
    echo $passwd
    Alternatively, you could use dialog or zenity instead of whiptail.
    Last edited by schragge; April 6th, 2013 at 02:34 PM.

  3. #13
    Join Date
    Apr 2013
    Beans
    10

    Re: Run a bash script on Terminal Startup

    Quote Originally Posted by schragge View Post
    Code:
    exec 3>&1
    passwd=`whiptail --passwordbox 'Enter password:' 7 21 2>&1 1>&3`
    exec 3>&-
    echo $passwd
    Alternatively, you could use dialog or zenity instead of whiptail.
    I had originally posted this in the absolute beginners section, so telling me that doesn't really tell me anything.

  4. #14
    Join Date
    May 2007
    Location
    Leeds, UK
    Beans
    1,675
    Distro
    Ubuntu

    Re: Run a bash script on Terminal Startup

    Whiptail displays various types of controls inside a terminal window. Things like information boxes, error boxes, text entry boxes, etc.

    Code:
    whiptail --msgbox "This is what Whiptail looks like" 10 30
    Zenity and Dialog do a similar job, but they display a separate window, rather than using the existing terminal. The window will match the desktop environment being used, so on default Ubuntu it will have an orange close button, etc.

    Code:
    zenity --info --text="This is what Zenity looks like"
    Screenshots of Whiptail and Zenity attached.

    For a password box with '*':

    Code:
    zenity --entry --text="Password" --hide-text
    Last edited by r-senior; April 6th, 2013 at 06:38 PM. Reason: Added password dialog
    Please create new threads for new questions.
    Please wrap code in code tags using the '#' button or enter it in your post like this: [code]...[/code].

  5. #15
    Join Date
    Feb 2013
    Beans
    Hidden!

    Re: Run a bash script on Terminal Startup

    The whole script done with whiptail:
    Code:
    #!/bin/bash -e
    
    get_password() {
      exec 3>&1
      REPLY=`whiptail --ok-button 'Unlock' --nocancel --passwordbox 'Enter password:' 7 21 2>&1 1>&3`
      exec 3>&-
      return 0
    }
    
    while
      get_password
      [[ $REPLY != 'password' ]]
    do
      whiptail --ok-button 'Try again' --msgbox 'Access denied!' 7 19
    done
    
    whiptail --ok-button 'Continue' --msgbox 'Access granted!' 7 19
    Last edited by schragge; April 6th, 2013 at 07:30 PM.

  6. #16
    Join Date
    Apr 2013
    Beans
    10

    Re: Run a bash script on Terminal Startup

    Quote Originally Posted by schragge View Post
    The whole script done with whiptail:
    Code:
    #!/bin/bash -e
    
    get_password() {
      exec 3>&1
      REPLY=`whiptail --ok-button 'Unlock' --nocancel --passwordbox 'Enter password:' 7 21 2>&1 1>&3`
      exec 3>&-
      return 0
    }
    
    while
      get_password
      [[ $REPLY != 'password' ]]
    do
      whiptail --ok-button 'Try again' --msgbox 'Access denied!' 7 19
    done
    
    whiptail --ok-button 'Continue' --msgbox 'Access granted!' 7 19
    Thanks, but that's still not really what I asked. I asked how to change MY SCRIPT to have stars instead of the password or the -s thing or whatever.

    It seems like nobody on this forum has any listening skills.

  7. #17
    Join Date
    Feb 2013
    Beans
    Hidden!

    Re: Run a bash script on Terminal Startup

    Well, you can read one character a time with read -sn1 and output an asterisk for it:
    Code:
    #!/bin/bash
    password=''
    while read -sn1 char; do
    [[ -z $c ]] && break;
    echo -n \*
    password+=$char
    done
    echo
    echo $password
    Last edited by schragge; April 8th, 2013 at 08:10 PM.

  8. #18
    Join Date
    Apr 2013
    Beans
    10

    Re: Run a bash script on Terminal Startup

    Quote Originally Posted by schragge View Post
    Well, you can read one character a time with read -sn1 and output an asterisk for it:
    Code:
    #!/bin/bash
    password=''
    while read -sn1 char; do
    [[ $c == '' ]] && break;
    echo -n \*
    password+=$char
    done
    echo
    echo $password
    How would I apply this to my script?

  9. #19
    Join Date
    Dec 2007
    Location
    Behind you!!
    Beans
    978
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Run a bash script on Terminal Startup

    Quote Originally Posted by thecodejunkie View Post
    How would I apply this to my script?
    Can I suggest that you run some of the code that you have been given, find the one that has the best output for your needs, analyse it and adapt to suit.
    What would you be learning if we write it for you?

    Bodsda
    computer-howto
    Linux is not windows
    Fluxbox & Flux menu how to
    Programming is an art. Learn it, Live it, Love it!


  10. #20
    Join Date
    Apr 2013
    Beans
    10

    Re: Run a bash script on Terminal Startup

    Quote Originally Posted by Bodsda View Post
    Can I suggest that you run some of the code that you have been given, find the one that has the best output for your needs, analyse it and adapt to suit.
    What would you be learning if we write it for you?

    Bodsda
    I would learn how to adapt it to my script.

    I could analyze someone else's code and figure out how they did it in a few minutes, or I could spend hours trying to apply it myself and get nowhere.

Page 2 of 2 FirstFirst 12

Bookmarks

Posting Permissions

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