Use shell scripts to load USB devices and copy files

Source: Internet
Author: User

Use shell scripts to load USB devices and copy files in Linux. If a USB device is inserted, use the mount command to load the device, the following is a Shell program for mounting a USB device and copying files. program requirements: www.2cto.com 1. during runtime, the user is prompted to enter "y" or "Y" to determine whether to mount the USB device, U Disk File/dev/sdc1if [$ ANS = "Y"-o $ ANS = "y"] then mount-t vfat/dev/sdc1/mnt/usb 2. Confirm whether to copy file to/root is best to use $? Check whether the copy is successful. $? -Eq 0, it indicates that the copy is successful 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. Check whether the FILE is copied to the USB device www.2cto.com 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 complete script: www.2cto.com #! /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 !!"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.