我正在尝试在新的 NAS 服务器上创建自己的云,但使用的脚本不起作用。
脚本:
#!/bin/bash
chown -R http:http /volume1/web/owncloud/
chown -R http:http /volume1/web/owncloud/apps/
chown -R http:http /volume1/web/owncloud/config/
chown -R http:http /volume1/web/owncloud/themes/
chown -R http:http /volume1/owncloud/
chown http:http /volume1/web/owncloud/.htaccess
find /volume1/web/owncloud/ -type f -print0 | xargs -0 chmod 777
find /volume1/web/owncloud/ -type d -print0 | xargs -0 chmod 777
find /volume1/owncloud/ -type d -print0 | xargs -0 chmod 777
chmod 777 /volume1/web/owncloud/.htaccess
答案如下:
Yamakhalah@Jarvis:/$ sudo -su root
Password:
sh-4.3# cd /
sh-4.3# sh /volume1/web/scripts/perm_upd.sh
/volume1/web/scripts/perm_upd.sh: line 2: $'\r': command not found
chown: cannot access ‘/volume1/web/owncloud/\r’: No such file or directory
chown: cannot access ‘/volume1/web/owncloud/apps/\r’: No such file or directory
chown: cannot access ‘/volume1/web/owncloud/config/\r’: No such file or directory
chown: cannot access ‘/volume1/web/owncloud/themes/\r’: No such file or directory
chown: cannot access ‘/volume1/owncloud/\r’: No such file or directory
/volume1/web/scripts/perm_upd.sh: line 8: $'\r': command not found
chown: cannot access ‘/volume1/web/owncloud/.htaccess\r’: No such file or directory
/volume1/web/scripts/perm_upd.sh: line 10: $'\r': command not found
chmod: invalid mode: ‘777\r’
Try 'chmod --help' for more information.
chmod: invalid mode: ‘777\r’
Try 'chmod --help' for more information.
chmod: invalid mode: ‘777\r’
Try 'chmod --help' for more information.
chmod: invalid mode: ‘777\r’
Try 'chmod --help' for more information.
chmod: invalid mode: ‘777\r’
Try 'chmod --help' for more information.
chmod: invalid mode: ‘777\r’
Try 'chmod --help' for more information.
/volume1/web/scripts/perm_upd.sh: line 12: $'\r': command not found
chmod: invalid mode: ‘777\r’
Try 'chmod --help' for more information.
chmod: invalid mode: ‘777\r’
Try 'chmod --help' for more information.
/volume1/web/scripts/perm_upd.sh: line 15: $'\r': command not found
sh-4.3#
有人可以解释一下为什么\r
到处都会出现这种情况吗?
答案1
您可能正在使用 Windows 样式文件并将其复制到您的 NAS。你必须将其转换为 Unix 风格。维基百科链接到更详细的解释。某些编辑器能够将文件保存为其他格式。如果您的编辑器无法执行此操作,您可以使用dos2unix
大多数 Linux 发行版可用的实用程序。
如果上述所有选项都没有帮助,这个堆栈溢出也许可以帮助你。