sh /app/scripts/test-i2c.sh > 1test var=cat 1test |awk '{print $2}'|tail -n 2 |sed -n '1p' if [ $var == "OK" ];then echo "test i2c pass" else echo "test i2c failed" exit 1 fi rm 1test逐行解读这段代码
时间: 2024-04-27 15:25:25 浏览: 18
这段代码是一段 Shell 脚本,逐行解读如下:
1. `sh /app/scripts/test-i2c.sh > 1test`:运行 `/app/scripts/test-i2c.sh` 脚本,并将输出重定向到文件 `1test` 中。
2. `var=cat 1test |awk '{print $2}'|tail -n 2 |sed -n '1p'`:将文件 `1test` 中倒数第二行的第二个单词赋值给变量 `var`。具体操作是,使用 `awk` 命令打印每行的第二个单词,然后使用 `tail` 命令取倒数第二行及之前的所有行,最后使用 `sed` 命令取第一行。
3. `if [ $var == "OK" ];then`:判断变量 `var` 是否等于字符串 "OK",如果是,则执行下一行代码,否则执行 `else` 后面的代码。
4. `echo "test i2c pass"`:输出字符串 "test i2c pass"。
5. `else`:如果 `if` 语句中的条件不成立,则执行该行代码之后的代码。
6. `echo "test i2c failed"`:输出字符串 "test i2c failed"。
7. `exit 1`:结束脚本并返回状态码 1。
8. `rm 1test`:删除文件 `1test`。
相关问题
nohup /app/scripts/run-portion.sh -b 2 -p $bpu_stress | grep -E 'BPU_PLAT|timeout|fail|error' > /userdata/bpu-stress.log &的用法
在 Linux 中,nohup 命令用于在后台运行命令,并忽略掉 HUP(hangup)信号,使得该命令即使在用户退出登录后也能继续运行。nohup 命令的语法如下:
```
nohup 命令 [参数] > 文件名 2>&1 &
```
其中,各部分的含义如下:
- 命令:要在后台运行的命令。
- 参数:命令的参数。
- 文件名:将命令的输出重定向到指定文件,如果不指定则默认输出到 nohup.out 文件。
- 2>&1:将标准错误输出重定向到标准输出。
- &:将命令放入后台运行。
在你给出的命令中,nohup 命令用于在后台运行 /app/scripts/run-portion.sh 脚本,并将输出重定向到 /userdata/bpu-stress.log 文件中。该命令的参数包括 -b 2 和 -p $bpu_stress,它们会被传递给 run-portion.sh 脚本。grep 命令用于过滤输出结果,只显示包含 BPU_PLAT、timeout、fail 或 error 的行。最后的 & 符号将该命令放入后台运行。
<builders> <org.jenkinsci.plugins.conditionalbuildstep.singlestep.SingleConditionalBuilder plugin="conditional-buildstep@1.4.2"> <condition class="org.jenkins_ci.plugins.run_condition.contributed.ShellCondition" plugin="run-condition@1.5"> <command>if git show --summary HEAD | grep -q -E "\(cherry picked from commit \b[0-9a-f]{5,40}\b\)"; then exit 1 fi</command> </condition> <buildStep class="hudson.tasks.Shell"> <command>./scripts/checkpatch.pl --min-conf-desc-length=1 --ignore GERRIT_CHANGE_ID -g HEAD </command> <configuredLocalRules/> </buildStep> <runner class="org.jenkins_ci.plugins.run_condition.BuildStepRunner$Run" plugin="run-condition@1.5"/> </org.jenkinsci.plugins.conditionalbuildstep.singlestep.SingleConditionalBuilder> <hudson.tasks.Shell> <command>NCPU=$(expr $(nproc --all ) / 2) make O=build-${BUILD_ID} -s defconfig make O=build-${BUILD_ID} -j$NCPU -s Image make O=build-${BUILD_ID} -j$NCPU -s modules make O=build-${BUILD_ID} INSTALL_MOD_PATH=../install-${BUILD_ID} -s modules_install mkdir -p install-${BUILD_ID}/boot/ KERNELVER=$(cat build-${BUILD_ID}/include/config/kernel.release 2> /dev/null) cat build-${BUILD_ID}/arch/arm64/boot/Image > install-${BUILD_ID}/boot/Image-$KERNELVER cp build-${BUILD_ID}/System.map install-${BUILD_ID}/boot/System.map-$KERNELVER cp build-${BUILD_ID}/.config install-${BUILD_ID}/boot/config-$KERNELVER tar -cJf install-${BUILD_ID}/linux-$KERNELVER.tar.xz -C install-${BUILD_ID}/ boot lib</command> <configuredLocalRules/> </hudson.tasks.Shell> <hudson.tasks.Shell> <command>cd $HOME/src/linux git fetch -p -t git pull </command> <configuredLocalRules/> </hudson.tasks.Shell> </builders> 这是一段Jenkins job的定义,请把它转成对应的JJB的yaml格式配置文件
对应的JJB的yaml格式配置文件如下所示:
```yaml
- builders:
- conditional-step:
conditional-buildstep@1.4.2:
condition:
shell-condition:
run-condition@1.5:
command: "if git show --summary HEAD | grep -q -E \"\\(cherry picked from commit \\b[0-9a-f]{5,40}\\b\\)\"; then exit 1 fi"
buildStep:
shell:
command: "./scripts/checkpatch.pl --min-conf-desc-length=1 --ignore GERRIT_CHANGE_ID -g HEAD"
configuredLocalRules: ""
runner:
run-build-step-runner:
run-condition@1.5: ""
- shell:
command: "NCPU=$(expr $(nproc --all ) / 2) make O=build-${BUILD_ID} -s defconfig make O=build-${BUILD_ID} -j$NCPU -s Image make O=build-${BUILD_ID} -j$NCPU -s modules make O=build-${BUILD_ID} INSTALL_MOD_PATH=../install-${BUILD_ID} -s modules_install mkdir -p install-${BUILD_ID}/boot/ KERNELVER=$(cat build-${BUILD_ID}/include/config/kernel.release 2> /dev/null) cat build-${BUILD_ID}/arch/arm64/boot/Image > install-${BUILD_ID}/boot/Image-$KERNELVER cp build-${BUILD_ID}/System.map install-${BUILD_ID}/boot/System.map-$KERNELVER cp build-${BUILD_ID}/.config install-${BUILD_ID}/boot/config-$KERNELVER tar -cJf install-${BUILD_ID}/linux-$KERNELVER.tar.xz -C install-${BUILD_ID}/ boot lib"
configuredLocalRules: ""
- shell:
command: "cd $HOME/src/linux git fetch -p -t git pull"
configuredLocalRules: ""
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)