• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

BASH Scripting Question

Netopia

Diamond Member
Greetings all!

I'm trying to make it easier for me to mount Windows shares on my Linux box. Currently I can type in something like:

mount -t smbfs -o username=netopia,password=mypass //windowsbox/share /directory/mount_point

I'd like to automate this (and all other smb mounting) with a simple script. If this were DOS, I could make a batch file that had something like the following in it"

mount -t smbfs -o username="%1",password="%2" //"%3"/"%4" /"%5"/"%6"

(or something close to that)

Let's say I called this batch file "mountit.bat". In order to use it, I'd just have to type at the command line:

mountit netopia mypass windowsbox share directory mount_point

and it would parse all those variable into the places I designated.

BUT... I'm not working with DOS. I can't find as simple a way to do this with BASH and I've looked through 3 books now! I know I could build some sort of array and then lookup to insert the varialbes, or do it in PERL (except that I don't know PERL), but I'm hoping there is an elegant solution as would be available in plain old DOS.

Am I looking for something that isn't there?

Thanks,

Joe
 
Yepo...

Just check out man fstab for details.

(most stuff has man files, some it is crap, but they should be there. Use man man for details, and then man -k keyword to look for stuff. If you end up with multiple files like fstab(1) and fstab(3), then you specify with something like man -S 3 fstab to get the one you want. Different man files are made sometimes for different audiances. User vs Developer vs Admin that sort of thing.)

Check out www.tldp.org for some help with this sort of thing, too. Check out the guide section. They have 2 good guides to deal with bash prompt and bash scripting. And also a system administrator guide that gives you a good overview about how the OS itself is setup and todo basic tasks like backups and users.
 
fstab(3)probably doesn't exist. Stick with man 5 fstab 😉

The different numbers each mean something.
1 General commands (tools and utilities).
2 System calls and error numbers.
3 Libraries.
3p perl(1) programmer's reference guide.
4 Device drivers.
5 File formats.
6 Games.
7 Miscellaneous.
8 System maintenance and operation commands.
9 Kernel internals.

EDIT: less NEEDS TO DIE
 
Originally posted by: Netopia
WOW... almost the same as the ancient DOS I learned circa 1985!

Thank you MUCHO!

Joe

It goes back to how C works. The arguments are passed to a C program as an array of strings, the first being the program name, and having the index of 0, the first arg having 1, second arg 2, etc etc. Actually it might be older than C but C is the oldest programming language I know.
 
Maybe I'm doing something wrong. I created a script that is as follows:

mount -t smbfs username=$1,password=$2 //$3/$4 /$5/$6

I called the script doit and gave it permissions of 775

I then called the script from the directory in which it resides with ./doit

I followed that with the variables (fake ones used here) so that my command looks like this:

./doit myname mypass winserver winshare local-directory mount-point

When executed, it just gives me the same help screen it would give you if you manually entered the command but used the wrong syntax. Do I need to be escaping something and don't know about it?

Thanks.... to everyone for all the input. Looks like I've got some reading to do at the sites pointed at.

Joe
 
Never mind! DOH!

I left out the -o before username.

EVERYTHING WORK PERFECTLY!

BTW, these aren't shares that I need access to all the time, but only every once in a while.. which is why I don't pemanently mount them.

MANY THANKS!

Joe
 
well, you can have them in /etc/fstab with the noauto option. They won't be automatically mounted, but you could mount them at any time by just using mount /mntpoint

On my laptop, I have entries for shares at home, work, and church, then I just need to mount /mnt/home and it's done.
 
Originally posted by: sciencewhiz
well, you can have them in /etc/fstab with the noauto option. They won't be automatically mounted, but you could mount them at any time by just using mount /mntpoint

On my laptop, I have entries for shares at home, work, and church, then I just need to mount /mnt/home and it's done.

WOW! That's great.... I'm gonna implement that!

Joe
 
Back
Top