Usb Suspend/Resume

#!/bin/bash
# Usb_Suspend-Resume.sh:the script could perform only suspend(every 10s) and resume 20s

# Path is the filename of the device usb driver, rep1ace by the actual usb name
path=1-2
# Iteration is the test times, initialized by 1000000000, the value can be revised by user
iteration="1000000000"
# The count of the test times for suspend and resume
count_sus="0"
count_res="0"
count="0"

# Execute the sub suspend and resume - Loop for iteration times
while [ $count -lt $iteration ]
do
	# Record date
	date "+%Y-%m/%d %H:%M:%S"
	# Usb suspend
	# Note when the kernel of system over 2.6.35, "level" should be replace by "control"
	echo auto > /sys/bus/usb/drivers/usb/$path/power/level
	# Idel for 10ms, the usb devices will be auto suspend by system
	# Note when the kernel of system over 2.6.38, "autosuspend" should be replace by "autosuspend_delay_ms"
	echo 10 > /sys/bus/usb/drivers/usb/$path/power/autosuspend
	# Usb Suspend 10s
	sleep 10
	# Get the state of the device usb
    rs=$(cat /sys/bus/usb/drivers/usb/$path/power/runtime_status)
    if [ "$rs" = "suspended" ]  
    then
		count_sus=$((count_sus+1))
        echo "usb is suspended for $count_sus times"
    fi
	# Usb resume
	# Note when the kernel of system over 2.6.35, "level" should be replace by "control"
	echo on > /sys/bus/usb/drivers/usb/$path/power/level
	# Usb Suspend 20s
	sleep 20
	# Get the state of the device usb
	res=$(cat /sys/bus/usb/drivers/usb/$path/power/runtime_status)
	if [ "$res" = "active" ]
    then
		count_res=$((count_res+1))
        echo "usb is actived for $count_res times"
    fi
	count=$((count+1))
done

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值