加入收藏 | 设为首页 | 会员中心 | 我要投稿 济南站长网 (https://www.0531zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 教程 > 正文

使用shell脚本达成USB设备的加载与文件复制

发布时间:2021-11-21 20:49:28 所属栏目:教程 来源:互联网
导读:在Linux操作系统中,如果插入一个USB设备,需要用mount挂载命令才能实现这个设备的加载,下面写一个USB设备挂载与文件复制的Shell程序,程序需求: 1、运行时,提示用户输入y或者Y,确定是否挂载USB设备,U盘文件/dev/sdc1 if[$ANS=Y -o $ANS = y] then moun

在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!!"

(编辑:济南站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读