Permission denied means that you are attempting something that is not allowed. Your question lacks some basic information that is needed to determine what exactly is not allowed.
To start at the beginning: example.sh
. How are you running this script? As bash examle.sh
? as ./example.sh
? If the latter: your script must be executable by you. Is the script executable by you? Use ls -l
to verify that.
As a side note: you should start your script with the line
#!/bin/bash
to be sure that bash is used to execute it.
Second side-note: $server
should be set. It may be set in your shell's environment, but you must be sure. However: not having set $server
to some correct value will probably give a different error message. You might echo the value of $server
just to be sure.
Next: can you execute /var/www/test/bin/change-sys-hostname
? The script is executable by the group www-data
. Are you in that group? Check with id
if www-data
is in your group-set.
Next is whether change-sys-hostname
has something in it that you are not allowed to do. change-sys-hostname
will probably call some other programs as well, which you should be allowed to execute. Especially: the script will probably write to some files that are only writable by root. So, sudo
will probably be required.
I've gone through some basic steps that you will need to do to find the solution. You will notice, that a lot of information in those steps is not in your question, and that information is needed to assess what is going on.
/var/www/test/bin/change-sys-hostname
do, and what is the value of$servername
?