从 Azure Linux VM 上的脚本启动防病毒扫描
Start antivirus scan from a script on Azure Linux VM
我在 Azure Linux 虚拟机中有一个 shell 脚本。 Azure Linux VM 在 it.The 中安装了 Sophos shell 脚本可以扫描存在于使用 savscan 命令扫描目录。挑战是,我们正在使用 azure 数据工厂 管道,它需要调用 azure 函数。 azure 函数应该能够通过 ssh 连接到 linux vm,并执行脚本。该函数应传递 azure 共享文件存储 的文件路径等参数,其中 Sophos 需要执行扫描。
我了解管道可以调用 http 触发的 azure 函数。但是我们如何从 azure 函数远程 ssh 进入 vm 和 运行 脚本。文件路径的参数也将来自数据工厂。
inotifywait -mr -e close_write "/xyz/abc/" |
while read dir eve file; do
echo "new file '$path$file' detected - start scan"
savscan -eec $path$file
if [ $? -eq 0 ]
then
echo "1"
else
echo "0"
fi
done
您的 ScriptPath
参数似乎有问题。如果您使用的是 Azure Automation,我们无法在其中放置静态脚本文件,但我们可以先下载我们的脚本并将其放置在 Azure Automation 的 "c:/temp" 文件夹中。
我自己做了一些测试,我把我的脚本放在 Azure 存储帐户中,在我需要 运行 这个脚本之前,我会把它下载到 Azure 自动化临时文件夹,这样我就可以指定一个路径到运行吧。
在自动化中尝试下面的 PS:
$appid = "<your Azure application ID>"
$passwd = "<your Azure application password>"
$tenant = "<tenant>"
$storageName = "<storage name>"
$containerName = "<container name>"
$scrtptName = "<script name>"
$storageResourceGroupName = "<storage group name>"
$vmName = "<vm name>"
$VMResourceGroupName = "<vm group name>"
$secpasswd = ConvertTo-SecureString -String $passwd -AsPlainText -Force
$cred = New-Object Management.Automation.PSCredential ($appid , $secpasswd)
login-AzAccount -Credential $cred -Tenant $tenant -ServicePrincipal
$storage = Get-AzStorageAccount -ResourceGroupName $storageResourceGroupName -Name $storageName
Get-AzStorageBlobContent -Container $containerName -Blob $scrtptName -Context $storage.Context -Destination "c:/temp"
$scriptPath = "c:/temp/$scrtptName"
$result = Invoke-AzVMRunCommand -VMname $vmName -ResourceGroupName $VMResourceGroupName -CommandId 'RunPowerShellScript' -ScriptPath $scriptPath
echo $result.Value
Remove-Item $scriptPath -Force
我导入的模块:
我将我的脚本放在我的存储帐户中,在这种情况下,它用于下载一些东西:
我的测试脚本内容:
$url = "https://download.microsoft.com/download/1/E/7/1E7B1181-3974-4B29-9A47-CC857B271AA2/English/X64/msodbcsql.msi"
$outpath = "c:/odbc.msi"
Invoke-WebRequest -Uri $url -OutFile $outpath
Azure 自动化测试及其结果:
可以看到文件已经下载成功。
顺便说一句,这里不需要使用远程 powershell,您可以使用 Azure VM 的 运行 命令功能直接 运行 您在 Azure VM 上的脚本。
干得好,斯坦利,我也会在 Ubuntu 机器上测试它。希望它有效:)
我在 Azure Linux 虚拟机中有一个 shell 脚本。 Azure Linux VM 在 it.The 中安装了 Sophos shell 脚本可以扫描存在于使用 savscan 命令扫描目录。挑战是,我们正在使用 azure 数据工厂 管道,它需要调用 azure 函数。 azure 函数应该能够通过 ssh 连接到 linux vm,并执行脚本。该函数应传递 azure 共享文件存储 的文件路径等参数,其中 Sophos 需要执行扫描。
我了解管道可以调用 http 触发的 azure 函数。但是我们如何从 azure 函数远程 ssh 进入 vm 和 运行 脚本。文件路径的参数也将来自数据工厂。
inotifywait -mr -e close_write "/xyz/abc/" |
while read dir eve file; do
echo "new file '$path$file' detected - start scan"
savscan -eec $path$file
if [ $? -eq 0 ]
then
echo "1"
else
echo "0"
fi
done
您的 ScriptPath
参数似乎有问题。如果您使用的是 Azure Automation,我们无法在其中放置静态脚本文件,但我们可以先下载我们的脚本并将其放置在 Azure Automation 的 "c:/temp" 文件夹中。
我自己做了一些测试,我把我的脚本放在 Azure 存储帐户中,在我需要 运行 这个脚本之前,我会把它下载到 Azure 自动化临时文件夹,这样我就可以指定一个路径到运行吧。
在自动化中尝试下面的 PS:
$appid = "<your Azure application ID>"
$passwd = "<your Azure application password>"
$tenant = "<tenant>"
$storageName = "<storage name>"
$containerName = "<container name>"
$scrtptName = "<script name>"
$storageResourceGroupName = "<storage group name>"
$vmName = "<vm name>"
$VMResourceGroupName = "<vm group name>"
$secpasswd = ConvertTo-SecureString -String $passwd -AsPlainText -Force
$cred = New-Object Management.Automation.PSCredential ($appid , $secpasswd)
login-AzAccount -Credential $cred -Tenant $tenant -ServicePrincipal
$storage = Get-AzStorageAccount -ResourceGroupName $storageResourceGroupName -Name $storageName
Get-AzStorageBlobContent -Container $containerName -Blob $scrtptName -Context $storage.Context -Destination "c:/temp"
$scriptPath = "c:/temp/$scrtptName"
$result = Invoke-AzVMRunCommand -VMname $vmName -ResourceGroupName $VMResourceGroupName -CommandId 'RunPowerShellScript' -ScriptPath $scriptPath
echo $result.Value
Remove-Item $scriptPath -Force
我导入的模块:
我将我的脚本放在我的存储帐户中,在这种情况下,它用于下载一些东西:
我的测试脚本内容:
$url = "https://download.microsoft.com/download/1/E/7/1E7B1181-3974-4B29-9A47-CC857B271AA2/English/X64/msodbcsql.msi"
$outpath = "c:/odbc.msi"
Invoke-WebRequest -Uri $url -OutFile $outpath
Azure 自动化测试及其结果:
顺便说一句,这里不需要使用远程 powershell,您可以使用 Azure VM 的 运行 命令功能直接 运行 您在 Azure VM 上的脚本。
干得好,斯坦利,我也会在 Ubuntu 机器上测试它。希望它有效:)