Amazon-Web-Services

在 EC2 中啟動帶有路徑修改的批處理腳本

  • October 18, 2018

我對 AWS 很陌生,但我想我了解如何部署 EC2 實例,我想做的是安裝 apache tomcat 以及在 Windows Server 2016 上使用實例創建中的使用者數據欄位所需的一切。我認為,我的問題來自於我需要為 jre、jdk 和 awscli 聲明新路徑這一事實。有沒有辦法做到這一點?

這是我的密碼:

<script>
powershell "& {$url='https://s3.amazonaws.com/aws-cli/AWSCLI64.msi';$clnt=new-object System.Net.WebClient;$clnt.DownloadFile($url,'C:\Users\Administrator\Downloads\installer.msi')}"
C:\Users\Administrator\Downloads\installer.msi /qn
setx PATH "%PATH%;C:\Program Files\Amazon\AWSCLI"
setx JAVA_HOME "C:\Program Files\Java\jdk1.8.0_181"
setx JRE_HOME "C:\Program Files\Java\jre1.8.0_181"
echo aws s3 cp s3://andrea-s-buckets999/followingScript2.bat C:\Users\Administrator\Downloads > C:\Users\Administrator\Downloads\followingScript.bat
echo aws s3 cp s3://andrea-s-buckets999/apache-tomcat-8.0.53.exe C:\Users\Administrator\Downloads >> C:\Users\Administrator\Downloads\followingScript.bat
echo aws s3 cp s3://andrea-s-buckets999/jdk-8u181-windows-x64.exe C:\Users\Administrator\Downloads >> C:\Users\Administrator\Downloads\followingScript.bat
echo aws s3 cp s3://andrea-s-buckets999/jre-8u181-windows-x64.exe C:\Users\Administrator\Downloads >> C:\Users\Administrator\Downloads\followingScript.bat
echo C:\Users\Administrator\Downloads\jdk-8u181-windows-x64.exe /s >> C:\Users\Administrator\Downloads\followingScript.bat
echo C:\Users\Administrator\Downloads\jre-8u181-windows-x64.exe /s >> C:\Users\Administrator\Downloads\followingScript.bat
echo C:\Users\AdministratorDownloads\followingScript2.bat >> C:\Users\Administrator\Downloads\followingScript.bat
C:\Users\Administrator\Downloads\followingScript.bat
</script>

您需要讀取路徑並附加新路徑並覆蓋它

在 PowerShell 程式碼中

$OldPath=(Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH).Path

$NewPath=$OldPath+’;C:\Something\...\....\bin’

引用自:https://serverfault.com/questions/934129