Find the answer to your Linux question:
Results 1 to 5 of 5
Hey guys! First of all I'm happy to see, that the folks have voted for a great president (again). Okay now my problem... I have two files with exactly same ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Nov 2012
    Posts
    3

    Weird problem with bash script


    Hey guys!

    First of all I'm happy to see, that the folks have voted for a great president (again).

    Okay now my problem...

    I have two files with exactly same content. And I've also two servers. Both are nearly the same, they are just hosted at different hoster, you know?

    So.. when I'm going to call them by "sh myscript.sh", on the one server it runs all commands successfully, this means without any errors. But on the other server there is something like "file or dir not found".

    Below the code inside the scripts:
    Code:
    #!/bin/bash
    
    chmod 755 -R /usr/share/nginx/{error,html};
    chown www-data:www-data -R /usr/share/nginx/{error,html};
    As far as you can see, I'm trying to fix the permissions because it's totally helpfully to reset them to the right values after making some modifications, you know.

    So, this works on server A but not on server B. I already set the chmod to u+x on both but without any changes.

    Maybe someone can give me a helping hand or just a information how to deal with this.

    Normally I use "sh" but now I'm just calling the script like ./myscript.sh which might be the right syntax. IDK btw..


    Ahh forgot to mention that the commands working perfectly itself but not by the script.

    Cheers!

  2. #2
    Linux Newbie
    Join Date
    Jun 2012
    Location
    SF Bay area
    Posts
    174
    I have one suggestion and one comment/question.

    First, the suggestion for how to figure out what's going on. Try the command "ls -ld /usr/share/nginx/{error,html}" and see if it finds both directories. If not, then that's where the error is coming from.

    And the question is, why do you want all the files in the nginx webserver "html" and "error" tree to be executable? That seems unnecessary and potentially problematic to me.

  3. #3
    Just Joined!
    Join Date
    Nov 2012
    Posts
    3
    Hi it's me again and I'm happy to see you've answered me.

    As I already wrote, doing the lines outside the script isn't the problem. Everything works fine as it should.

    The question for chmod that files is legit, but it's needed in this case because I want to serve them to my websites. It isn't possible without these rights.

    Cheers!

  4. #4
    Linux Newbie
    Join Date
    Jun 2012
    Location
    SF Bay area
    Posts
    174
    If you can't serve HTML without the "execute" permission set, them something is very odd... Read access should be sufficient for the files and read/execute for the directories. But the plain files shouldn't need "execute". As for what's wrong, I dunno... I'd probably use something like this personally.

    Code:
    find /usr/share/nginx/error /usr/share/nginx/html -type d -exec chmod 755 {} \; -exec chown www-data:www-data {} \; -print
    find /usr/share/nginx/error /usr/share/nginx/html -type f -exec chmod 644 {} \; -exec chown www-data:www-data {} \; -print

  5. #5
    Just Joined!
    Join Date
    Nov 2012
    Posts
    3
    Thanks agian for your reply. I've made small modifications and it's now possible to set chmod to 555.

    Anyways the problem with the method how I run the script still exists.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •