wget and run/remove bash script in one line

15,518

Solution 1

I think you might need to actually execute it:

wget http://sitehere.com/install.sh -v -O install.sh; ./install.sh; rm -rf install.sh

Also, if you want a little more robustness, you can use && to separate commands, which will only attempt to execute the next command if the previous one succeeds:

wget http://sitehere.com/install.sh -v -O install.sh && ./install.sh; rm -rf install.sh

Solution 2

I like to pipe it into sh. No need to create and remove file locally.

wget http://sitehere.com/install.sh -O - | sh

Solution 3

I think this is the best way to do it:

wget -Nnv http://sitehere.com/install.sh && bash install.sh; rm -f install.sh

Breakdown:

  • -N or --timestamping will only download the file if it is newer on the server
  • -nv or --no-verbose minimizes output, or -q / --quiet for no "wget" output at all
  • && will only execute the second command if the first succeeds
  • use bash (or sh) to execute the script assuming it is a script (or shell script); no need to chmod +x
  • rm -f (or --force) the file regardless of what happens (even if it's not there)
  • It's not necessary to use the -O option with wget in this scenario. It is redundant unless you would like to use a different temporary file name than install.sh
Share:
15,518
amanada.williams
Author by

amanada.williams

Updated on June 06, 2022

Comments

  • amanada.williams
    amanada.williams 7 months
    wget http://sitehere.com/install.sh -v -O install.sh; rm -rf install.sh
    

    That runs the script after download right and then removes it?