Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add files via upload #1961

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions it-support-engineer/assignment.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
```
#以下是使用Bash脚本的示例来完成这个任务:
#!/bin/bash

#解压缩日志文件
log_data=$(gzip -dc interview_data_set.gz)

#按行分隔日志数据
log_lines=$(echo "$log_data" | tr '\n' '\r')

#遍历日志行并提取关键信息
while read -d $'\r' line; do
#提取数据
deviceName=$(echo $line | awk '{print $1}')
processId=$(echo $line | awk '{print $2}')
processName=$(echo $line | awk '{print $3}')
description=$(echo $line | awk '{$1=$2=$3=""; print $0}' | sed -e 's/^[[:space:]]*//')
timeWindow=$(echo $line | awk '{print $(NF-1)}')
numberOfOccurrence=$(echo $line | awk '{print $NF}')

#将数据转换为JSON格式
json_data=$(jq -n \
--arg deviceName "$deviceName" \
--arg processId "$processId" \
--arg processName "$processName" \
--arg description "$description" \
--arg timeWindow "$timeWindow" \
--arg numberOfOccurrence "$numberOfOccurrence" \
'{deviceName: $deviceName, processId: $processId, processName: $processName, description: $description, timeWindow: $timeWindow, numberOfOccurrence: $numberOfOccurrence}')

#发送POST请求
curl -X POST -d "$json_data" -H 'Content-Type: application/json' https://foo.com/bar
done <<< "$log_lines"

#以下是使用PowerShell的示例脚本来完成这个任务:

#解压缩日志文件
$log_data = Get-Content -Path "interview_data_set.gz" -Raw | Out-String | ForEach-Object { [System.Text.Encoding]::UTF8.GetString($_) }

#按行分隔日志数据
$log_lines = $log_data -split "`n"

#遍历日志行并提取关键信息
foreach ($line in $log_lines) {
#提取数据
$deviceName = $line.Split()[0]
$processId = $line.Split()[1]
$processName = $line.Split()[2]
$description = $line.Split()[3..($line.Split().Count-3)] -join " "
$timeWindow = $line.Split()[-2]
$numberOfOccurrence = $line.Split()[-1]
#将数据转换为JSON格式
$json_data = @{
deviceName = $deviceName
processId = $processId
processName = $processName
description = $description
timeWindow = $timeWindow
numberOfOccurrence = $numberOfOccurrence
} | ConvertTo-Json

#发送POST请求
Invoke-WebRequest -Uri "https://foo.com/bar" -Method POST -Body $json_data -ContentType "application/json"
}
```