How to execute a Bash script from Github?

Arcticooling

Say this I have the following file my_cool_file.sh in a Git repository in Github (or BitBucket for that matter) named my_cool_repo. The file is a script used to install ConfigServer's well known CSF-LFD software:

#!/bin/bash
cd /usr/src
rm -fv csf.tgz
wget https://download.configserver.com/csf.tgz
tar -xzf csf.tgz
cd csf
sh install.sh
sed -i "s/TESTING = "1"/TESTING = "0"/g" /etc/csf/csf.conf
csf -r
perl /usr/local/csf/bin/csftest.pl
# sh /etc/csf/uninstall.sh

How can one execute this Bash script (a .sh file) directly from Github, via command line?

Videonauth

Load the file (make sure you use the raw file, otherwise you load the HTML page!) with wget using its exact URL and then pipe the output to bash:

Here's an example with clarifications:

wget -O - https://raw.githubusercontent.com/<username>/<project>/<branch>/<path>/<file> | bash

From the manpage for the wget command:

   -O file
   --output-document=file
       The documents will not be written to the appropriate files, but all
       will be concatenated together and written to file.  If - is used as
       file, documents will be printed to standard output, disabling link
       conversion.  (Use ./- to print to a file literally named -.)

       Use of -O is not intended to mean simply "use the name file instead
       of the one in the URL;" rather, it is analogous to shell
       redirection: wget -O file http://foo is intended to work like wget
       -O - http://foo > file; file will be truncated immediately, and all
       downloaded content will be written there.

So outputting to - will actually write the files content to STDOUT and then you simply pipe it to bash or whatever shell you prefer. If you script needs sudo rights you need to do sudo bash at the end so the line becomes:

wget -O - https://raw.githubusercontent.com/<username>/<project>/<branch>/<path>/<file> | sudo bash

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to execute git commands from bash script?

From Dev

How to execute a bash script?

From Dev

How to execute shell commands in a loop from within a bash script?

From Dev

Execute Perl Script from Bash script

From Dev

Unable to execute a bash script in background from another bash script

From Dev

Cannot execute Bash script from PHP

From Dev

Execute bash script with params from Javascript

From Dev

Bash script to read from a file and execute commands

From Dev

Bash script to read from a file and execute commands

From Dev

Execute complex command from bash script

From Dev

Execute random file from a folder in a bash script

From Dev

How to execute a script from a browser?

From Dev

How to execute a bash script as sbt task?

From Dev

How to execute SQL command with parameters in bash script

From Dev

How to execute custom command in bash script

From Dev

How to execute a command within a bash script?

From Dev

How to execute recurring Bash script at specific times?

From Dev

how to execute a bash command in a python script

From Dev

How to execute the following commands in a bash script?

From Dev

How to execute bash script on a remote machine asynchronously

From Dev

How do I execute a xfconf-query command from a bash script launched with sudo?

From Dev

How do I execute a bash script on my Vagrant from PhpStorm on a Windows PC

From Dev

How to execute bash (in script) with own .bash_logout file?

From Dev

Go: execute bash script

From Dev

Bash Script - Will not completely execute

From Java

How to execute a Python script from the Django shell?

From Dev

How to execute a webpack module from a <script>?

From Dev

How to execute shell script from hubot

From Dev

How to execute a Matlab script from C++

Related Related

  1. 1

    How to execute git commands from bash script?

  2. 2

    How to execute a bash script?

  3. 3

    How to execute shell commands in a loop from within a bash script?

  4. 4

    Execute Perl Script from Bash script

  5. 5

    Unable to execute a bash script in background from another bash script

  6. 6

    Cannot execute Bash script from PHP

  7. 7

    Execute bash script with params from Javascript

  8. 8

    Bash script to read from a file and execute commands

  9. 9

    Bash script to read from a file and execute commands

  10. 10

    Execute complex command from bash script

  11. 11

    Execute random file from a folder in a bash script

  12. 12

    How to execute a script from a browser?

  13. 13

    How to execute a bash script as sbt task?

  14. 14

    How to execute SQL command with parameters in bash script

  15. 15

    How to execute custom command in bash script

  16. 16

    How to execute a command within a bash script?

  17. 17

    How to execute recurring Bash script at specific times?

  18. 18

    how to execute a bash command in a python script

  19. 19

    How to execute the following commands in a bash script?

  20. 20

    How to execute bash script on a remote machine asynchronously

  21. 21

    How do I execute a xfconf-query command from a bash script launched with sudo?

  22. 22

    How do I execute a bash script on my Vagrant from PhpStorm on a Windows PC

  23. 23

    How to execute bash (in script) with own .bash_logout file?

  24. 24

    Go: execute bash script

  25. 25

    Bash Script - Will not completely execute

  26. 26

    How to execute a Python script from the Django shell?

  27. 27

    How to execute a webpack module from a <script>?

  28. 28

    How to execute shell script from hubot

  29. 29

    How to execute a Matlab script from C++

HotTag

Archive