LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Script to automate VMWare Tools Install Error: No such file or directory (https://www.linuxquestions.org/questions/programming-9/script-to-automate-vmware-tools-install-error-no-such-file-or-directory-4175557501/)

JockVSJock 10-29-2015 03:09 PM

Script to automate VMWare Tools Install Error: No such file or directory
 
So I wrote a simple Bash script to try and automate the install of VMWare Tools for all of our RHEL Servers. I was doing multiple commands from the CLI successfully, so I'm trying to automate it. However I continue to get the following error output.

Code:


./vmwaretools_install: line 19: cd: /media/VMWare Tools/: No such file or directory
 
unmount VMWare Tools Install ISO Before Proceeding...

tar (child): *.tar.gz:  Cannot open:  No such file or directory
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting now
./vmwaretools_install:  line 28: cd: vmware-tools-distrib: No such file or directory
./vmwaretools_install: line28: ./vmware-install.pl: No such file or directory


Here is the code:
Code:


#!/bin/bash

echo
echo "Remove Old VMWare Tools First..."
echo

/usr/bin/./vmware-uninstall-tools.pl

echo
echo "Remove old VMWare Tools Directory and Create New Directory "
echo
rm -rf /tmp/vmwaretools/* ; mkdir -p /tmp/vmwaretools

echo
echo "Mount VMWare Tools ISO from vSphere now"
echo
read -p "Press [ENTER] to continue VMWare Tools Install Once ISO is Mounted..."

cd /media/VMWare\ Tools/ ; cp -R * /tmp/vmwaretools

echo
echo "unount VMWare Tools Install ISO Before Proceeding..."
echo

#umount /dev/sr0 /media/VMWare\ Tools/
eject /dev/sr0

cd /tmp/vmwaretools ; tar -zxvf *.tar.gz ; cd vmware-tools-distrib ; ./vmware-install.pl


In trying to troubleshoot, I've done the following:

Code:


head -l vmwaretools_install | od -c

0000000 # ! / b i n / b a s h \n
0000015

I've also deleted out #!/bin/bash line incase there is an extra space in there that I can't see and then put it back in and still the same error.

I've check permission and set the following:

Code:

chmod +x /root/scripts/vmwaretools_uninstall

ls -l rwxr-xr-x 1 root root

Not sure what else to check at this time.

MensaWater 10-30-2015 08:14 AM

What happens if you replace the escape with double quotes?
e.g.
cd "/media/VMWare Tools/"
rather than:
cd /media/VMWare\ Tools/

JockVSJock 10-30-2015 08:38 AM

Tried what you recommended and still getting the following error message.

Code:


./vmwaretools_install: line 19: cd: /media/VMWare Tools/: No such file or directory

I noticed something odd, for some reason my bash script is being copied to /tmp/vmwaretools.

Line 19 in the code is the following:

Code:


19 cd "/media/VMWare Tools/" ; cp -R * /tmp/vmwaretools

So I can't figure out why its coping the bash script into /tmp/vmwaretools?

MensaWater 10-30-2015 09:12 AM

Quote:

Originally Posted by JockVSJock (Post 5442319)

I noticed something odd, for some reason my bash script is being copied to /tmp/vmwaretools.

Line 19 in the code is the following:

Code:


19 cd "/media/VMWare Tools/" ; cp -R * /tmp/vmwaretools

So I can't figure out why its coping the bash script into /tmp/vmwaretools?

Because the cd failed but the cp -R * worked (i.e. it copied from your pwd rather than "VMWare Tools" as you were still in pwd when it got to the cp command.

MensaWater 10-30-2015 09:18 AM

On your original question when I do a test using either the double quotes or the escape (\) it works in a simple script for me.

That makes me wonder: Did you actually mount the ISO as /media/VMWare Tools before hitting return when you ran the script?
That is your script isn't mounting the ISO but rather asking you to do so then hit return. Presumably you are doing that mount in a separate session. Do you see it mounted when you run "df -h" after the mount? (Maybe you're mount is mounting it as /media/VMWare rather than /media/VMWare Tools because you didn't escape or quote in your mount command line?)

JockVSJock 10-30-2015 09:32 AM

Quote:

Originally Posted by MensaWater (Post 5442338)
Because the cd failed but the cp -R * worked (i.e. it copied from your pwd rather than "VMWare Tools" as you were still in pwd when it got to the cp command.

I don't understand why the cd isn't working? Maybe because I have to go back to vSphere and click a button, "Install VMware Tools." That's why I have the read line in the script, so the end user has time to click that button, then press enter on the keyboard to continue the script. Otherwise during the vmware-install.pl it won't complete successfully because the VMware Tools ISO is still mounted.

When mounting the VMware Tools iso, it shows the following:

Code:


/dev/sr0 on /media/VMware Tools type iso9660 (ro,nosuid,nodev,uhelper=udisks,uid=0,gid=0,ohcharset=utf8,mode=0400,dmode=0500)


MensaWater 10-30-2015 10:18 AM

And what does df show after the mount?

What do you see if you do the cd manually after the mount and type pwd?

By the way why cd to the mount anyway? Why not just do:
cp -R "/media/VMWare Tools/*" /tmp/vmwaretools

JockVSJock 10-30-2015 11:36 AM

Code:

df -ha

/dev/sr0  62M  62M  0  100%  /media/VMware Tools


Code:

# cd /media
# pwd
/media
# cd VMware\ Tools/
# pwd
/media/VMware Tools

Since I'm new to this, I thought it was best to change to that directory and cp -R "/media/VMware Tools/*" /tmp/vmwaretools.

MensaWater 10-30-2015 12:23 PM

Quote:

Originally Posted by JockVSJock (Post 5442410)
Code:

df -ha

/dev/sr0  62M  62M  0  100%  /media/VMware Tools


Code:

# cd /media
# pwd
/media
# cd VMware\ Tools/
# pwd
/media/VMware Tools



There is a mismatch between your original script and what you are mounting as.
Script has uppercase "W" after VM but what you just wrote shows you're mounting with lower case "w"
i.e. VMWare vs VMware.

Linux is case sensitive so it sees VMWare, VMware, vMware, VmWare etc... all as different names. If you are mounting with the lower case "w" then you should use the lower case "w" in the script.

JockVSJock 10-30-2015 01:10 PM

Well, I posted a response, however I got logged out of the website and lost all of that info.

HOWEVER, I found a solution, which did the trick:

Code:


/bin/bash -c "cp -R /media/VMware\ Tools/* /tmp/vmwaretools"

Looking online, the script isn't having the issue, its the Bash shell. So I had to give the cp command a path to /bin/bash -c. Still not really understanding Globbing files, however if i keep doing these, I will figure it out.

thanks for you help

suicidaleggroll 10-30-2015 01:35 PM

Quote:

Originally Posted by JockVSJock (Post 5442475)
Well, I posted a response, however I got logged out of the website and lost all of that info.

HOWEVER, I found a solution, which did the trick:

Code:


/bin/bash -c "cp -R /media/VMware\ Tools/* /tmp/vmwaretools"

Looking online, the script isn't having the issue, its the Bash shell. So I had to give the cp command a path to /bin/bash -c. Still not really understanding Globbing files, however if i keep doing these, I will figure it out.

thanks for you help

None of that was the problem, the problem was your script was using an upper case W:
/media/VMWare\ Tools
instead of
/media/VMware\ Tools

Your debugging process is very odd...why didn't you just go straight to line 19 and look at why your cd was failing, since that's the part of the script that was failing???

Copy-paste that line from your script into the terminal, see if it fails, why it fails, fix it, and then make that change to the script.

Focusing on execute permissions and character dumps of the shebang makes absolutely no sense to me when the script is failing all the way down on line 19 with a VERY clear error:
Quote:

cd: /media/VMWare Tools/: No such file or directory
Which means either the ISO file is not mounted, or you have an error/typo in your mount location.

JockVSJock 10-30-2015 01:43 PM

One last thing.

There was a globbing issue when it was running the ./vmware-install.pl. I believe this is because these commands are being ran from the Bash Shell Script Vs from the CLI.

I'm running the program as root, along with user and group is root.

suicidaleggroll 10-30-2015 01:45 PM

Quote:

Originally Posted by JockVSJock (Post 5442495)
There was a globbing issue when it was running the ./vmware-install.pl. I believe this is because these commands are being ran from the Bash Shell Script Vs from the CLI.

There is no difference when you run a command inside a bash script versus running it on the interactive bash shell.

JockVSJock 10-30-2015 02:21 PM

Quote:

Originally Posted by suicidaleggroll (Post 5442496)
There is no difference when you run a command inside a bash script versus running it on the interactive bash shell.

Then why the Globbing warning/output from their script?

suicidaleggroll 10-30-2015 02:30 PM

What warning/output?


All times are GMT -5. The time now is 01:00 PM.