Unix Script Not Giving Desired Result

Hi all,

I am using the command:

mount -t cifs //10.41.5.242/warehouse -o username=warehouse,password=password /mnt/warehouse_win

This command works ok, however when I put it in a script it returns with the error:

"mount error: can not change directory into mount target /mnt/warehouse_win"

I have whittled down my script so it now only contains the mount command to try and eliminate the problem so i've obviously donw something wrong somewhere.

Cheers
K

techmissAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

medveddCommented:
Please double-check that mount point exists:

file /mnt/warehouse_win
ls -l /mnt

techmissAuthor Commented:
Yes the mount point exists, as I ran the command outside of the script and it worked fine.

Below is by desired mount point.

[root@server /]# ls -l /mnt
total 4
drwxr-xr-x  2 root root 4096 Apr 22 13:59 warehouse_win

Thanks

K
jfaubiontxCommented:
Please post the script. From what I see here this should work. As a test I used the following script:

#!/bin/bash

# Mount the directory
mount -t cifs //192.168.1.50/PDFStorage -o username=jfaubion,password=MyPassWd /mnt/warehouse_win

This mounts with no issues on both Fedora 12 and Centos 5.4. Granted not Red Hat exactly but the closest flavors I had available tonight.

Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

techmissAuthor Commented:
Hi,

Code is below, when I run this script using ./scriptname.sh I now get the message:

": bad interpreter: No such file or directory"

When I run the same mount command at the command line it mounts successfully.

Thanks

K


#!/bin/bash
#mount the directory
mount -t cifs //10.41.5.242/warehouse -o username=warehouse,password=password /mnt/warehouse_win

Open in new window

jfaubiontxCommented:
Two issues I know that can cause the bad interpreter with a script like this. First, do you have bash installed in /bin? Do a "which bash" to make sure bash is located where we think it is. I'm fairly sure it will be in /bin since I think you have the second issue.

I suspect you have edited your script in windows and transferred it to the Linux box. This could have been done by editing the script in notepad and then saving it to a shared folder. Install the dos2unix package. If you have yum this can be done with "yum install dos2unix" to install it. An alternative would be to use tr to remove the conflicting returns. To do this use this:

cp scriptname.sh scriptname.tmp
tr -d '\r' < scriptname.tmp > scriptname.sh
rm -f scriptname.tmp

This will remove the returns from the file which should allow it to run properly.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jfaubiontxCommented:
So did that fix the issue?
joolsSenior Systems AdministratorCommented:
did you whittle your script down a lot?

I have to agree with jfaubiontx about the error above, I'd bet you've got ^M chars at the end of the lines.

I'm also wondering if /mnt is mounted by something else before, I only ask because you did not show the interpreter error in your original Q.

techmissAuthor Commented:
Was the second option - script was indeed edited in notepad.

Thanks.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.