Quote:
Originally posted by Jake_da_Snake
code:
#!/bin/bash:::: I suppose thiz 2 lines just should be there?
|
This line has to be there since it is telling that bash will be used for interpreting this program(if you use other shells then you should look into those.
Quote:
|
iam=`whoami` :::: I have no idea what this line does
|
the whoami command basically tells you which user is running the current session...so like my user name under my linux box is rmanocha...so if i type whoami on the command line...i get back rmanocha.I store this value in a variable called iam.the "`" you see around the command is only to tell bash that you are supposed to execute this command.This is how i store who is using the current session into a variable..i could have probably used this in the if statement too but i am like that.
Quote:
|
if[ $iam = rmanocha ];then :::same goes for this line.
|
This line is basically like any other if statment in C/C++/JAVA etc.i am only checking who is the current user....my current user name is stored in iam and then i compare the value in i am with rmanocha(the user who should be able to mount the share).If this statement is true...that is if iam holds 'rmanocha' then go onto the next statement else just finish the program.
Quote:
Assuming that I have 3 users. linuxuser1, linuxuser2 and linuxuser3. How would I mount
windows nt shared folders for linuxuser1?
|
all you will have to do is write a if statement with something like this:
Code:
if [ $iam = linuxuser1 || $iam = linuxuser2 || $iam = linuxuser3 ];then
mount blah(put whatever it is you want to mount here) > /dev/null
Quote:
eventhough I was trying to avoid fstab I put the following line in fstab just to see
what would happen.
//windowsNT/shared /shared smbfs username=username,password=password,noauto
|
Even though i dont know much about samba(never really used it too much) i would say that maybe going with smbmount in the file we are writing could be a better solution.anyways...if the above fstab entry is correct...then there is still one problem you will run into.you are saying noauto...which means that this share will not be mounted automatically on boot(well to come to think of it...maybe you dont want to mount it when the machine boots...only when someone logs out...so i guess you can suit yourself). another thing you might want to add to this line is user so your fstab entry should look something like this:
Code:
//windowsNT/shared /shared smbfs username=username,password=password,noauto,user
This migh become easier if you actually look into the docs of smbmount and see if you can mount the shares using that program.
what you should have is this:
Code:
#!/bin/bash
iam=`whoami`
if [ $iam = linuxuser1 ];then
mount /shared 2>/dev/null
fi
this should mount the shares just fine as described through fstab.the "2>/dev/null' is only to not display any error messages that this program may produce...since .bashrc is executed everytmie a shell will open hence the share might already be mounted when the user opens another shell and this will create a error message from mount.to get rid of that message you put it to /dev/null
hope this helps.let me know if it does.
a good site to learn bash programming is
here