使用shell脚本实现USB设备的加载与文件复制
作者:网络转载 发布时间:[ 2013/2/21 10:16:48 ] 推荐标签:
在Linux操作系统中,如果插入一个USB设备,需要用mount挂载命令才能实现这个设备的加载,下面写一个USB设备挂载与文件复制的Shell程序,程序需求:
1、运行时,提示用户输入“y”或者“Y”,确定是否挂载USB设备,U盘文件/dev/sdc1
if[$ANS="Y" -o $ANS = "y"]
then mount -t vfat /dev/sdc1 /mnt/usb
2、确定是否复制文件到/root
好用$?判断一下是否复制成功,$? -eq 0,表示复制成功
while[$ANS="Y" -o $ANS = "y"]
do
ls -lha /mnt/usb
echo "type the filename you want to copy"
read FILE
cp /mnt/usb/"$FILE" /root
3、确定是否复制文件到USB设备中
echo "Do you want to copy files to USB(y/n)"
read ANS
while[$ANS="Y" -o $ANS = "y"]
do
ls -lh /root
echo "type the filename you want to copy"
read FILE
cp /root/"$FILE" /mnt/usb
if[ $? -eq 0];then
echo "Finished"
else
echo "Error"
fi
echo "any other files(Y/N)"
read ANS
done
完整的脚本:
#!/bin/bash
#autousb
echo "Welcome to USB"
echo "Do you want load USB(Y/N)"
read ANS
if[$ANS="Y" -o $ANS = "y"];
then mount -t vfat /dev/sdc1 /mnt/usb
echo "Do you want to copy files to /root(y/n)?"
read ANS
while[$ANS="Y" -o $ANS = "y"]
do
ls -lha /mnt/usb
echo "type the filename you want to copy"
read FILE
cp /mnt/usb/"$FILE" /root
if[ $? -eq 0];then
echo "Finished"
else
echo "Error"
fi
echo "any other files(Y/N)"
read ANS
done
fi
echo "Do you want to copy files to USB(y/n)"
read ANS
while[$ANS="Y" -o $ANS = "y"]
do
ls -lh /root
echo "type the filename you want to copy"
read FILE
cp /root/"$FILE" /mnt/usb
if[ $? -eq 0];then
echo "Finished"
else
echo "Error"
fi
echo "any other files(Y/N)"
read ANS
done
echo "Do you want to umount?(y/n)"
read ANS
if[$ANS="Y" -o $ANS = "y"];then
umount /mnt/usb
else
echo "umount error"
fi
echo "GoodBye!!"
相关推荐
更新发布
功能测试和接口测试的区别
2023/3/23 14:23:39如何写好测试用例文档
2023/3/22 16:17:39常用的选择回归测试的方式有哪些?
2022/6/14 16:14:27测试流程中需要重点把关几个过程?
2021/10/18 15:37:44性能测试的七种方法
2021/9/17 15:19:29全链路压测优化思路
2021/9/14 15:42:25性能测试流程浅谈
2021/5/28 17:25:47常见的APP性能测试指标
2021/5/8 17:01:11