Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have to do the following from within a bash script. The /VMNFS/ folder is present on linux box, from where script is run, and is mapped to the machine into which i am ssh'ing, as an NFS at /vmfs/volumes/VMNFS/. The second cd command doesn't work, neither with symbolic path name nor physical pathname. Why? and How to rectify this?

ssh -2 root@  /bin/sh  <<\EOF
vmfile_path=`grep / vmvar_file`
cd $datastore_path                && echo "The present working directory is" `pwd -P`
esxi_vmfile_path_sub=`pwd -P`     && echo "variable value is" $esxi_vmfile_path_sub
esxi_vmfile_path=`echo $vmfile_path | sed "s:/VMNFS:$esxi_vmfile_path_sub:"`             
cd "$esxi_vmfile_path" 

The current working directory is  /vmfs/volumes/65335ec4-46d12e41
variable value is /vmfs/volumes/65335ec4-46d12e41
can't cd to /vmfs/volumes/65335ec4-46d12e41/TPAE7.5/
share|improve this question
up vote 0 down vote accepted

Does it work when you manually change the directory on the command line? If not, it could be that you simply don't have the permissions to see that directory.

Other than that, it seems you're using an incredibly complicated way to change a directory. What's wrong with

ssh -2 root@  /bin/sh  <<EOF
cd "/vmfs/volumes$(grep -m 1 / vmvar_file)"

Also, you might consider double-quoting all your variable assignments, in case they result in values with spaces. Talking of spaces, if your $esxi_vmfile_path contains spaces, it might also try to change to the wrong directory.

share|improve this answer
i am logging in as root, and yes, it works manually (i.e. when directories are hardcoded). Only when i am using variables, the cd command is not working. – Bhavya Maheshwari Feb 4 '13 at 12:06
But it is absolutely essential for me to use variables. – Bhavya Maheshwari Feb 4 '13 at 12:21
Updated my answer. – Stefan Seidel Feb 4 '13 at 13:02

Stupid thought... check to see that you do not have spaces at the end of your paths in the vmar_file

share|improve this answer
That’s probably not an issue with the script as presented, because it doesn’t use quotes as often as it should. But a good point; something for the OP to watch out for in general. – Scott Jun 9 '14 at 22:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .