diff --git a/it-support-engineer/assignment.txt b/it-support-engineer/assignment.txt new file mode 100644 index 000000000..ccd0c5423 --- /dev/null +++ b/it-support-engineer/assignment.txt @@ -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" +} +``` \ No newline at end of file