Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

#!/bin/bash
ssh -2 root@9.124.119.17  /bin/sh  <<\EOF
vmfile_path=`grep / vmvar_file`
datastore_path=/vmfs/volumes/VMNFS/
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" 
EOF


***Output***:
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
add comment

2 Answers

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

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

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
add comment

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 at 22:25
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.