linux – 检测是否安装了(NTFS)驱动器.如果没有,那么安装它
作者:互联网
我想将USB驱动器与位于NTFS分区上的文件夹同步,该文件夹在启动时未安装.我找到了一个命令:rsync -axu / media / USB / folder / home / user / folder.但我必须安装NTFS驱动器.
如何从脚本中检测是否安装了NTFS驱动器,如果不安装它?我使用Linux(Ubuntu).
这是在您的帮助下修改的小脚本(原始版本为here)!
#!/bin/bash
## CONFIG SECTION
MOUNT_DRIVE=/dev/disk/by-id/scsi-SATA_Hitachi_HTS5416_SB3404GRGJRKBS-part5
MOUNT_POINT=/media/Windows/
# Local folder to sync with
SYNC_LOC=/media/Windows/vasia/Disertatie/
# Device folder to sync with
SYNC_DEV=Disertatie
#
## SCRIPT SECTION
#verify if the drives are mounted
if mount | grep -q "/media/Windows/"; then
#device is mounted
echo "Windows NTFS Drive is mounted!"
else
#device is not mounted,let's mount it
mount $MOUNT_DRIVE $MOUNT_POINT
fi
# Wait for thumbdrive to settle
sleep 10
# Synchronize thumbdrive with local
rsync -axu /media/DISK_IMG/${SYNC_DEV}/ ${SYNC_LOC}/
# Synchronize local with thumbdrive
#rsync -axu ${SYNC_LOC}/ /media/disk/${SYNC_DEV}/
# Inform user that synchronization is complete.
zenity --title "Thumbdrive Sync" \
--info --text "File synchronization complete."
解决方法:
关于如何做到这一点,还有另外一种解决方案.您可以在NTFS文件系统中创建一个文件,然后检查该文件是否存在.在您的情况下,其他解决方案可能更好.但是,如果您需要检查是否安装了NFS或SMB文件系统,有时最好检查文件,因为您要确保它不仅已安装,而且可以访问.然后你会这样做:
if [ ! -f /your/mounted/fs/mount-check.txt ];
then
echo "Here you have to put your mount command."
fi
标签:linux,shell,mount,automounting 来源: https://codeday.me/bug/20190810/1639772.html