LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 06-18-2004, 01:02 AM   #1
TankerKevo
Member
 
Registered: Sep 2003
Location: Tampa
Distribution: RH9 & FC2
Posts: 55

Rep: Reputation: 15
Question How to Make a Linux Script File


I recently added an iomega zip drive to my system. I'd like to create a script for mounting and unmounting the drive, but alas...I don't know how to make scripts!

I need it to do this:

Mounting

Instead of having to type:
iw -m /dev/sda -mp /zip
I want to type:
mzip

Unmounting

Instead of:
iw -u /dev/sda
I want:
uzip

Once I learn how to create this script I'm going to make scripts for my CDROMs and floppy.

Last edited by TankerKevo; 06-18-2004 at 01:05 AM.
 
Old 06-18-2004, 01:19 AM   #2
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
You don't necessarily need a script to do that. You can, but I would guess most people would suggest setting up an alias instead. I'll give you equivalents for both (alias and script).

For an alias, you have two choices on where to put it: /etc/bashrc or ~/.bashrc

Making a change to /etc/bashrc will make the alias available to every user on the system. Making the change to ~/.bashrc will make the alias available only for that particular user. Define an alias like this:
Code:
alias mzip='iw -m /dev/sda -mp /zip'
After finishing, source the file you changed. Either source /etc/bahrc or source ~/.bashrc

You only have to source the file for any shells you currently have open. The next time you log in, the alias will be ready automatically.

Now, for the shell script...

Open a text editor and type in this (or copy-paste):
Code:
#!/bin/bash

iw -m /dev/sda -mp /zip

exit 0
Save the file as mzip (the name you want to use for the command). Then execute the following command:
chmod a+x mzip

That command makes the script executable. Now, if you want to type "mzip" on the command line no matter where you are, then move the mzip file to a spot somewhere in your PATH variable. A good place would probably be /usr/local/bin

And that's all there is to it.
 
Old 06-18-2004, 04:42 AM   #3
TankerKevo
Member
 
Registered: Sep 2003
Location: Tampa
Distribution: RH9 & FC2
Posts: 55

Original Poster
Rep: Reputation: 15
Alrite thanks!

I'm doing this now! I'll let everyone know how I did this afternoon!
 
Old 06-18-2004, 07:39 PM   #4
TankerKevo
Member
 
Registered: Sep 2003
Location: Tampa
Distribution: RH9 & FC2
Posts: 55

Original Poster
Rep: Reputation: 15
Worked great!!!

I used the alias feature on my mount and unmount commands and created a script w/ a symbolic link in my rc.3 and rc.5 directories using "mprobe ppa&" so that my CPU recognizes that there's a zip drive automatically at start up!

Iomega Zip 100 Parallel (So that people looking for the same solution find it when searching.)

Thanks Dark Helmet for the knowledgeable advice!

TankerKevo

Last edited by TankerKevo; 06-18-2004 at 07:41 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl cgi Script can`t make file.Why? ZairSadiqov Linux - Software 1 11-22-2006 07:22 AM
can i make a script or program make a phone call? nephish Linux - Software 2 08-15-2005 09:02 PM
How to make a file inherit script permissions antony.booth Linux - Security 4 03-11-2005 05:04 AM
Make file, dos, linux The_Nerd Programming 1 05-29-2004 11:36 PM
A way to script file transfer from Linux to windows? jkcunningham Linux - Networking 11 11-21-2002 07:58 PM


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

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration