1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

why does mkdir -p fail silently?

Discussion in 'Mac Programming' started by dancks, Jun 30, 2013.

  1. macrumors member

    dancks

    #1
    shell script:

    Code:
    #http://stackoverflow.com/questions/17204092/bash-script-trouble-interpretting-input/17204840?noredirect=1#17204840
    #!/bin/bash
    addr=$(ifconfig -a | ./check_ip)
    relpath=$(./strip /users/me/Desktop/place_on_server/ $2)
    if [[ $1 = "DIR" ]]
    then
      shift
      #( IFS=/; echo ssh "root@$addr" mkdir -p "/var/www/media/$*"; )
      #( IFS=/; ssh "root@$addr" "mkdir -p /var/www/media/$*"; "chmod 755 /var/www/media/$*";)
      #( ssh "root@$addr" "mkdir -p /var/www/media/$relpath"; "chmod 755 /var/www/media/$relpath"; )
      ( ssh "root@$addr" "cd /var/www/media"; "mkdir -p $relpath/"; "chmod 755 $relpath/"; )
    elif [[ $1 = "F" ]]
    then
      shift
      last=$#
      file=${!last}
      #( IFS=/; echo rsync "$file" "root@$addr:/var/www/media/$*" )
      #( IFS=/; chmod 755 "$*"; rsync "$file" "root@$addr:/var/www/media/$*"; )
      ( IFS=/; chmod 755 "$*"; rsync "$file" "root@$addr:/var/www/media/$*"; )
    else
      echo "Unknown command '$1'"
    fi
    
    I test that in terminal I get:

    Code:
    me$ ./upload DIR /users/me/Desktop/place_on_server/test-folder
    ./upload: line 11: mkdir -p test-folder/: No such file or directory
    ./upload: line 11: chmod 755 test-folder/: No such file or directory
    
    EDIT: The title post is inaccurate. I did get an error-message. The thing is I have to use -p option because the folder in question may actually be embedded in another folder that doesn't exist on my server, but still. And I'm logged in as root.
     
  2. macrumors member

    #2
    Your quotes are wrong. As it stands, you will ssh onto the server and do a cd, then the ssh ends. then you try to execute "mkdir -p test_folder/" on the local machine. But the quotes make that one token, so it is literally looking for an executable named "mkdir -p test_folder/" (with embedded spaces), and isn't finding it.

    Presumably you want the mkdir to be executed in the ssh, so make sure all the commands you want to execute on the server (including the semicolons) are enclosed in a single set of quotes. i.e.:

    Code:
    ssh "root@$addr" "cd /var/www/media; mkdir -p $relpath/; chmod 755 $relpath/"
    The parens are also extraneous.
     
  3. macrumors member

    dancks

    #3
    thank you
     

Share This Page