bash 脚本中的 chmod 问题

bash 脚本中的 chmod 问题

我有一个脚本来格式化驱动器、设置权限 (777)、复制文件、更改权限 (555) 以及卸载和弹出影院 DCP 的驱动器。目前一切正常,但我遇到了 chmod 问题。文件以适当的权限从源驱动器复制到目标驱动器,因此我不确定错误是什么。脚本和输出如下:

脚本

#! /bin/bash

#Format Drive

sudo umount /dev/sda1 
sudo parted -s /dev/sda mktable msdos 
sudo parted /dev/sda mkpart primary ext3 1 100% 
sudo wipefs -a /dev/sda1 
sudo mkfs.ext3 -I 128 -L "DCP" /dev/sda1

#Update /etc/fstab

sudo mount -a

#Mount Drive

sudo mount /dev/sda1 /media/mynamehere/

#Set Permissions

sudo chmod -R 777 /media/mynamehere/DCP

#Copy Files to Target Drive

sudo rsync -av ~/Desktop/Source_Folder/ /media/mynamehere/DCP/

#Set Permissions

sudo chmod -R 555 /media/mynamehere/DCP

#Unmount Disk

sudo umount /dev/sda1

#Eject Disk

sudo eject /dev/sda1

输出

Information: You may need to update /etc/fstab.

mke2fs 1.43.5 (04-Aug-2017)                                               
Creating filesystem with 3931904 4k blocks and 983040 inodes
Filesystem UUID: 68e0a893-3fe8-4daf-8ba0-3d5a285903fc
Superblock backups stored on blocks: 
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done   

chmod: cannot access '/media/mynamehere/DCP': No such file or directory

sending incremental file list

created directory /media/mynamehere/DCP
./
ASSETMAP
CPL_DCP_SHR-2D_F-185_EN_51_2K_20180125_IOP_OV_a3b962d5-4e8d-46.xml
DCP_SHR-2D_F-185_EN_51_2K_20180125_IOP_OV_2707c99f-e757-44_j2c.mxf
DCP_SHR-2D_F-185_EN_51_2K_20180125_IOP_OV_fb719829-110f-4b_pcm.mxf
PKL_DCP_SHR-2D_F-185_EN_51_2K_20180125_IOP_OV_608bffb5-7d2d-49.xml
VOLINDEX

sent 1,117,023,702 bytes  received 185 bytes  248,227,530.44 bytes/sec
total size is 1,116,750,369  speedup is 1.00

答案1

从你的输出:

chmod: cannot access '/media/mynamehere/DCP': No such file or directory

很简单,该目录DCP只有在您创建它之后才存在(使用下一行中的 rsync)。

由于您以 root 身份运行每个命令,因此chmod 777提前运行应该不会产生任何影响(正如脚本其余部分成功运行的事实所证明的那样)。

相关内容