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

Thread: Bash Script

  1. #11
    Join Date
    Apr 2012
    Beans
    7,256

    Re: Bash Script

    Here's what I'd do

    Create a simple bash script somewhere with only the administrative commands you want to execute e.g.

    Code:
    #!/bin/bash
    
    add-apt-repository ppa:Repository
    apt-get update
    apt-get install package
    I created a directory in my home directory called 'scripts' and put it there, but the exact location doesn't matter. Mark it as executable, either through the file manager or from a terminal using 'chmod'

    Code:
    chmod +x /path/to/myscript
    Now right-click on the Xubuntu desktop and select 'Create launcher...' and enter the 'Command' as

    Code:
    gksu /path/to/myscript
    Give it a name and add a comment about what the script does, and check the 'Run in terminal' box. After that, you should be able to run it by double-clicking the launcher, at which point 'gksu' will pop up a dialog box for you to enter your password and then run the script in a terminal.
    Attached Images Attached Images

  2. #12
    Join Date
    Apr 2012
    Beans
    192
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Bash Script

    Yes that work fine steeldriver--thanks. I will do that. I wonder why it does not work when you run the same script without the launcher?
    “In the beginning God created the heavens and the earth.”

  3. #13
    Join Date
    Oct 2013
    Location
    europe
    Beans
    155
    Distro
    Lubuntu Development Release

    Re: Bash Script

    Quote Originally Posted by garyzw View Post
    Code:
    xfce4-terminal -e "sudo add-apt-repository ppa:bhdouglass/indicator-remindor" 
    
    sudo apt-get update && apt-get install indicator-remindor
    Which brings up the Terminal and asks for the password I enter the password and it adds the ppa but won't go on past that to apt-get update && apt-get install indicator-remindor.
    I wonder why it does not work when you run the same script without the launcher?
    Because you did not read carefully what the other users wrote.
    The following (amended) one-liner
    Code:
    xfce4-terminal  -e "sudo add-apt-repository ppa:bhdouglass/indicator-remindor  && apt-get update && apt-get install indicator-remindor"
    would (IMHO) work, because sudo is (in general) remembered when used in same terminal session (or as the pros would put it "in same tty", i. e. /dev/pts/<id>).
    The gist of it is that you have to put ALL three commands in those quotes, because xfce4-terminal will cause anything else following that to be sent to /dev/null.
    Last edited by syntaxerror74; August 22nd, 2014 at 03:01 PM.

  4. #14
    Join Date
    Apr 2012
    Beans
    192
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Bash Script

    Quote Originally Posted by syntaxerror74 View Post
    Because you did not read carefully what the other users wrote.

    Code:
    xfce4-terminal  -e "sudo add-apt-repository ppa:bhdouglass/indicator-remindor  && apt-get update && apt-get install indicator-remindor"
    would (IMHO) work, because sudo is (in general) remembered when used in same terminal session (or as the pros would put it "in same tty", i. e. /dev/pts/<id>).
    The gist of it is that you have to put ALL three commands in those quotes, because xfce4-terminal won't be able to execute anything else beyond that.
    Yes i read what others wrote and also tried that it again in a script and it did not work. It opens the Termnial I enter the password then the Terminal closes--no pressing enter to add ppa
    “In the beginning God created the heavens and the earth.”

  5. #15
    Join Date
    Nov 2011
    Location
    /dev/root
    Beans
    Hidden!

    Re: Bash Script

    Quote Originally Posted by garyzw View Post
    Yes i read what others wrote and also tried that it again in a script and it did not work. It opens the Termnial I enter the password then the Terminal closes--no pressing enter to add ppa
    Did you try with an additional bash command? It works for me.

    Code:
    xterm -hold -e bash -c "sudo add-apt-repository ppa:bhdouglass/indicator-remindor  && apt-get update && apt-get install indicator-remindor"
    From
    Code:
    man bash
    Code:
           -c string
                     If  the -c option is present, then commands are read from string.  If there are argu‐
                     ments after the string, they are assigned to the positional parameters, starting with
                     $0.

  6. #16
    Join Date
    Jul 2011
    Location
    /Europe/Netherlands
    Beans
    378
    Distro
    Kubuntu 22.04 Jammy Jellyfish

    Re: Bash Script

    Don't you also need sudo on the commands after the && operator when they require root privileges?

    This doesn't work here:
    Code:
    sudo apt-get update && apt-get upgrade
    The first command works, but the second is executed without root privileges.

    This does work:
    Code:
    sudo apt-get update && sudo apt-get upgrade

  7. #17
    Join Date
    Nov 2011
    Location
    /dev/root
    Beans
    Hidden!

    Re: Bash Script

    Quote Originally Posted by Erik1984 View Post
    Don't you also need sudo on the commands after the && operator when they require root privileges?

    This doesn't work here:
    Code:
    sudo apt-get update && apt-get upgrade
    The first command works, but the second is executed without root privileges.

    This does work:
    Code:
    sudo apt-get update && sudo apt-get upgrade
    Good catch Erik

  8. #18
    Join Date
    Aug 2011
    Location
    47°9′S 126°43W
    Beans
    2,172
    Distro
    Ubuntu 16.04 Xenial Xerus

    Re: Bash Script

    I wonder what is the purpose of adding a ppa/repo in a script.... this is typically something you do once for all.
    Warning: unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.

  9. #19
    Join Date
    Apr 2012
    Beans
    192
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Bash Script

    Quote Originally Posted by ofnuts View Post
    I wonder what is the purpose of adding a ppa/repo in a script.... this is typically something you do once for all.
    I have several computers with Xubuntu and having a script with mutilple ppa/repo's is very handy if you install multiple programs on different computers it makes it easy. Also if for what every reason I need to re-install I can have a script with all my installed programs and ppa/repo's to quickly re-install them after a fresh install.

    The following is the code that worked perfectly Thanks to Pilosopong Tasyo who helped me with this.

    Code:
    #!/bin/bash
    
    # if this script was not launched from a terminal, restart it from a terminal
    
    if [[ ! -t 0 && -x /usr/bin/x-terminal-emulator ]]; then
       /usr/bin/x-terminal-emulator -e "bash -c \"$0 $*; read -s -p 'Press enter to close...'\""
       exit
    fi
    
    sudo add-apt-repository ppa:repo
    sudo apt-get update
    sudo apt-get install package
    “In the beginning God created the heavens and the earth.”

  10. #20
    Join Date
    Oct 2005
    Location
    /root
    Beans
    Hidden!
    Distro
    Ubuntu 16.04 Xenial Xerus

    Re: Bash Script

    You're welcome, garyzw (I'm P.T. from the other forum BTW).
    Give a man a ghoti, and he'll eat for a day. Teach him how to ghoti, and he'll eat for life.

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
  •