Page 1 of 2 12 LastLast
Results 1 to 10 of 20

Thread: Run a bash script on Terminal Startup

  1. #1
    Join Date
    Apr 2013
    Beans
    10

    Run a bash script on Terminal Startup

    I have Ubuntu 12.

    I made a simple script to ask for a password before I can get in the terminal, but how do I make it so it runs this script every single time I start Terminal? Here's the script:

    Code:
    clear
    
    echo EVTech TermLock v1.0.0
    echo #
    echo Enter password now:
    read password
    
    if [ $password = password ]
        then echo #
        echo Access granted! Press enter to continue.
        read key
        clear
        else echo #
        echo Access denied! Press enter to try again.
        read key
        bash EVTermLock.sh
    fi

  2. #2
    Join Date
    Apr 2008
    Location
    LOCATION=/dev/random
    Beans
    5,767
    Distro
    Ubuntu Development Release

    Re: Run a bash script on Terminal Startup

    You could call it from your ~/.bashrc file which gets run every time you open a terminal.
    Just edit your ~/.bashrc and add the following to the bottom...
    Code:
    source /path/to/script.sh
    You do realise that your script provides no extra security and is trivial to disable don't you ?
    Cheesemill

  3. #3
    Join Date
    Apr 2013
    Beans
    10

    Re: Run a bash script on Terminal Startup

    Quote Originally Posted by Cheesemill View Post
    You could call it from your ~/.bashrc file which gets run every time you open a terminal.
    Just edit your ~/.bashrc and add the following to the bottom...
    Code:
    source /path/to/script.sh
    You do realise that your script provides no extra security and is trivial to disable don't you ?
    I do know that it's stupid and simple and provides no real protection, but I'm really just doing it to learn.

    How do I get to said "~/.bashrc"?

  4. #4
    Join Date
    Apr 2009
    Beans
    250
    Distro
    Xubuntu 20.04 Focal Fossa

    Re: Run a bash script on Terminal Startup

    Its in your home directory. The dot '.' before the filename makes it hidden. Try ls -a to see it in a directory listing.

  5. #5
    Join Date
    Apr 2013
    Beans
    10

    Re: Run a bash script on Terminal Startup

    I figured it out, had to unhide the files. Thanks! It works now. I'll perfect the script

  6. #6
    Join Date
    Apr 2013
    Beans
    10

    Re: Run a bash script on Terminal Startup

    Now if I wanted to hide the user input with *'s, how would I do that?

    Slightly updated script:
    Code:
    clear
    
    echo EVTech TermLock Protocol v1.0.1
    echo #
    echo Enter password now:
    read password
    
    if [ $password = password ]
        then echo #
        echo Access granted! Press enter to continue.
        read key
        clear
        else echo #
        echo Access denied! Press enter to try again.
        read key
        bash ~/Documents/Scripts/Bash/EVTermLock.sh
    fi

  7. #7
    Join Date
    Apr 2013
    Beans
    14

    Re: Run a bash script on Terminal Startup

    read -s key

  8. #8
    Join Date
    Apr 2013
    Beans
    10

    Re: Run a bash script on Terminal Startup

    Quote Originally Posted by savi3000 View Post
    read -s key
    Keep in mind that this is in fact the Absolute Beginners Section, I have no idea how to use that in the proper context.

  9. #9
    Join Date
    Jan 2007
    Location
    Netherlands
    Beans
    2
    Distro
    Edubuntu 6.10 Edgy

    Re: Run a bash script on Terminal Startup

    Just replace your original line:
    read key
    with
    read -s key
    Output when entering the password will be empty.

  10. #10
    Join Date
    Sep 2006
    Beans
    8,627
    Distro
    Ubuntu 14.04 Trusty Tahr

    built-in commands

    read is built into bash. If you want to know more about the other options for it and the other built-in commands, then the place to look is the manual page for bash. It will give you more than you want to know, but it's an invaluable reference and well worth learning to navigate.

Page 1 of 2 12 LastLast

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
  •