Linux exp script to test remote ARM through SSH/login

[localroot]$ cat stresstest.exp
#!/usr/bin/expect

set timeout 60
set prompt {~ # }
#exp_internal 1

set mtc 0
set starttime [exec date ]
set ip [lindex $argv 0]
set NUM 0

while { 1 } {
    set sleeptime [expr int(rand() * 10 + 30)]
    set NUM [ expr $NUM + 1 ]
    set DATE [exec date ]
    send_user "No. $NUM, Waiting $sleeptime secondsi , starttime is $starttime , now $DATE \n"
    sleep $sleeptime
    spawn ssh root@$ip

    expect "*?assword" { send "rootpassword\r" }

    expect {
        "MTC-DVT" {
            set mtc 1
            exp_continue
        }
        $prompt {
            if {$mtc == 1} {
                send "mount -t ext4 /dev/mmcblk0p1 /flash\r"
                set mtc 0
                exp_continue
            }
            send "cat /proc/mounts\r"
        }
    }

    expect $prompt {
        send "dd if=/dev/mmcblk0p1 bs=1 count=1600000 skip=\$((0x438)) of=/tmp/data & dmesg & reboot\r"
    }

    expect eof
    wait
} 

猜你喜欢

转载自blog.csdn.net/hushui/article/details/108638273