Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jun 30, 2013, 09:59 PM   #1
dancks
macrumors member
 
Join Date: Nov 2009
why does mkdir -p fail silently?

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.
dancks is offline   0 Reply With Quote
Old Jun 30, 2013, 10:21 PM   #2
dylanryan
macrumors newbie
 
Join Date: Aug 2011
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.
dylanryan is offline   1 Reply With Quote
Old Jul 1, 2013, 12:10 PM   #3
dancks
Thread Starter
macrumors member
 
Join Date: Nov 2009
thank you
dancks is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 08:32 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC