2

I'm trying to run this command line in Azure Batch node start up task

sudo wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u161-b12/2f38c3b165be4555a1fa6e98c45e0808/jdk-8u161-linux-x64.rpm" && sudo yum localinstall jdk-8u161-linux-x64.rpm -y

However, It always failed with this kind of error in the log file

Usage: wget [OPTION]... [URL]...

Try `wget --help' for more options.

Looks like it doesnt understand the && operator. I've remotely logged in the VM via ssh and try the command and it worked. Please advice if you've got any experience with this. Any help is appreciated! Thank you

Quan Hoang
  • 45
  • 5

1 Answers1

10

You should start the command with /bin/bash -c and then put the command in double quotes, escaping the inner double quotes.

So something like this should work: /bin/bash -c "sudo wget --no-cookies --no-check-certificate --header \"Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie\" \"http://download.oracle.com/otn-pub/java/jdk/8u161-b12/2f38c3b165be4555a1fa6e98c45e0808/jdk-8u161-linux-x64.rpm\" && sudo yum localinstall jdk-8u161-linux-x64.rpm -y"

gezzahead
  • 1,196
  • 1
  • 11
  • 20
  • Additionally, it's recommended to use the appropriate [User Identities](https://learn.microsoft.com/azure/batch/batch-user-accounts) with elevation rather than explicit `sudo`. – fpark Mar 21 '18 at 15:18
  • No problem - if it worked could you please mark it as the correct answer? Thanks – gezzahead Aug 24 '18 at 09:03
  • How can we run multiple commands, one runs on cmd and other on @powershell on Windows server ? – Mike143 Jun 28 '19 at 15:37