PDA

View Full Version : why does mkdir -p fail silently?




dancks
Jun 30, 2013, 09:59 PM
shell script:


#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:


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.



dylanryan
Jun 30, 2013, 10:21 PM
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.:

ssh "root@$addr" "cd /var/www/media; mkdir -p $relpath/; chmod 755 $relpath/"

The parens are also extraneous.

dancks
Jul 1, 2013, 12:10 PM
thank you