在 EC2 中启动带有路径修改的批处理脚本

在 EC2 中启动带有路径修改的批处理脚本

我对 AWS 还很陌生,但我想我已经了解如何部署 EC2 实例,我想做的是在 Windows Server 2016 上使用实例创建中的用户数据字段安装 apache tomcat 以及所需的一切。我认为,我的问题来自于我需要为 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>

答案1

您需要读取路径并附加新路径并覆盖它

在 PowerShell 代码中

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

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

相关内容