在脚本中执行时“ln”的行为不同

在脚本中执行时“ln”的行为不同

我正在尝试通过脚本安装 Guacamole。当需要将存储在 /etc/guacamole 中的文件链接到 tomcat8 目录时,在 shell 中执行以下行可以正常工作:

ln -s /etc/guacamole/ /usr/share/tomcat8/.guacamole

结果是:

/usr/share/tomcat8/.guacamole/[files]

但是当通过脚本执行相同的命令时,结果是:

/usr/share/tomcat8/.guacamole/guacamole/[files]

这会导致错误。

这是完整的脚本:

#!/bin/bash

apt-get update
apt-get upgrade -y
apt-get dist-upgrade -y

apt-get install -y apt-transport-https 
apt-get install -y libcairo2-dev libjpeg62-turbo-dev libpng12-dev libossp-uuid-dev libfreerdp-dev libpango1.0-dev libssh2-1-dev libtelnet-dev libvncserver-dev libpulse-dev libssl-dev libvorbis-dev libwebp-dev tomcat8 apache2 php5 libapache2-mod-php5 php5-curl git make gcc 

a2dissite 000-default
rm -r /var/www/*
a2enmod php5
a2enmod proxy_http ssl
php5enmod curl

wget http://downloads.sourceforge.net/project/guacamole/current/source/guacamole-server-0.9.9.tar.gz
tar -xzf guacamole-server-0.9.9.tar.gz

cd guacamole-server-0.9.9
./configure --with-init-dir=/etc/init.d
make
make install

cd ..
rm -r guacamole-server-0.9.9

wget http://downloads.sourceforge.net/project/guacamole/current/binary/guacamole-0.9.9.war
mv guacamole-0.9.9.war /var/lib/tomcat8/webapps/guacamole.war

update-rc.d guacd defaults
ldconfig

cd

mkdir /usr/share/tomcat8/.guacamole
mkdir /etc/guacamole

cp guacamole.properties /etc/guacamole/
cp user-mapping.xml /etc/guacamole/

cp guacamole.apache.conf /etc/apache2/sites-available/
a2ensite guacamole.apache.conf

ln -s /etc/guacamole/ /usr/share/tomcat8/.guacamole

/etc/init.d/guacd start
/etc/init.d/tomcat8 restart
/etc/init.d/apache2 restart

答案1

如果链接已经存在,则将在指向该链接的目录内创建新链接。理想情况下,您应该在创建链接之前删除/移动它

/bin/rm /usr/share/tomcat8/.guacamole
ln -s /etc/guacamole/ /usr/share/tomcat8/.guacamole

编辑:我看到您在脚本中创建了这个目录。只需删除该行即可。然后它应该可以工作。从脚本中删除以下行

mkdir /usr/share/tomcat8/.guacamole

相关内容