Wget and run / delete bash script in one line

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

Run the script after loading on the right, and then delete it?

+4
source share
4 answers

I think you might need to execute it:

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

In addition, if you want to increase reliability a little, you can use && to separate commands that will try to execute the next command only if the previous successfully completed:

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

I like to squander it in sh. There is no need to create and delete a file locally.

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

+44
source

I think this is the best way to do this:

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

Structure:

  • -N or --timestamping will only download the file if it is new on the server
  • -nv or --no-verbose minimizes output or -q / --quiet without output << 27> at all
  • && will only execute the second command if the first is successful
  • use bash (or sh ) to execute the script, provided that it is a script (or shell script); no need chmod +x
  • rm -f (or --force ) file no matter what happens (even if it is missing)
  • In this case, it is not necessary to use the -O option with wget . This is redundant if you do not want to use a different temporary file name than install.sh
+1
source

You load the first statement and delete it in the last expression. You need to add a line to fix the file by adding:

 ./install.sh 
0
source

Source: https://habr.com/ru/post/1438476/


All Articles