test-definitions/blob/master/auto-test/busybox/busybox.sh

#!/bin/sh
# Busybox smoke tests.

# shellcheck disable=SC1091
#回显命令执行及其参数
set -x
#进入目录,分先后执行两个脚本文件,再返回到当前目录
cd ../../utils
    . ./sys_info.sh
    . ./sh-test-lib
cd -
#Test user id
#检查是否是root 用户
if [ `whoami` != 'root' ]; then
    echo "You must be the superuser to run this script" >&2
    exit 1
fi
#发行版的版本,目前只针对centos 来安装包
case $distro in
    "centos")
		#安装四个package
        yum install gcc -y
        yum install make -y
        yum install bzip2 -y
        yum install wget -y
		#下载busybox的tar包
        wget https://busybox.net/downloads/busybox-1.27.2.tar.bz2
		#检查下载是否成功
        print_info $? download-busybox
		#加压tar包
        tar -jxvf busybox-1.27.2.tar.bz2
		#检查解压是否成功
        print_info $? tar-busybox
		#进入到目录开始编译busybox,并检查编译是否成功
        cd busybox-1.27.2/
        make defconfig
        make
        print_info $? make-busybox
        ;;
esac
#针对centos和debian busybox执行的方式不同
case $distro in
    "centos")
     commond="./busybox"
     ;;
    "debian")
     commond="busybox"
     ;;
esac
#这就就是执行busybox的中包含的pwd命令
$commond pwd
#通过$? 建厂busybox的pwd 命令是否执行成功
print_info $? busybox-pwd


$commond mkdir dir
print_info $? busybox-mkdir

$commond touch dir/file.txt
print_info $? busybox-touch

$commond ls dir/file.txt
print_info $? busybox-ls

$commond cp dir/file.txt dir/file.txt.bak
print_info $? busybox-cp

$commond rm dir/file.txt.bak
print_info $? busybox-rm

$commond echo 'busybox test' > dir/file.txt
print_info $? busybox-echo

$commond cat dir/file.txt
print_info $? busybox-cat

$commond grep 'busybox' dir/file.txt
print_info $? busybox-grep

# shellcheck disable=SC2016
$commond awk '{printf("%s: awk\n", $0)}' dir/file.txt
print_info $? busybox-awk

$commond free
print_info $? busybox-free

$commond df
print_info $? busybox-df
#检查是否存在busybox的进程
count=`ps -aux | grep busybox | wc -l`
#如果busybox的进程大于0,则通过pidof 得到这个进程的pid后,再通过kill 杀掉这个进程
if [ $count -gt 0 ]; then
    kill -9 $(pidof busybox)
    print_info $? kill-busybox
fi
#如果发行版是centos的话,在测试结束后,删掉这三个package
case $distro in
    "centos")
     yum remove gcc -y
     yum remove make -y
     yum remove bzip2 -y
     ;;
esac

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值