LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 05-10-2006, 05:25 AM   #1
ashley_31
Member
 
Registered: May 2006
Location: India
Distribution: RedHat Enterprise Linux (Kernel 2.6)
Posts: 42

Rep: Reputation: 15
user defined shell commands


hello friends..
i am working on red hat linux (kernal 2.6). Although it has a GUI to work upon but still i wish to work on its shell and be perfect in that too.
Can anybody tell how to create our own shell commands.
i mean that supposedly if some one has to access the cdrom and he does not remember all those shell commands to mount the cd-rom and all that, then i define a command in such a way that it contains all those things required to access the cdrom and the other person just writes the command and he can access the cdrom well..
Hope you people are able to understand my problem..
Please help me out if possible.
 
Old 05-10-2006, 05:37 AM   #2
slackie1000
Senior Member
 
Registered: Dec 2003
Location: Brasil
Distribution: Arch
Posts: 1,037

Rep: Reputation: 46
hi there,
you are looking for an alias or maybe a shell script.
you should start looking for /etc/profile for aliases.
regards,
slackie1000
 
Old 05-10-2006, 05:42 AM   #3
imagineers7
Member
 
Registered: Mar 2006
Distribution: BackTrack, RHEL, FC, CentOS, IPCop, Ubuntu, 64Studio, Elive, Dream Linux, Trix Box
Posts: 310

Rep: Reputation: 30
Try this

Hi ashley,
Write following in a file suppose mnt.sh
file mnt.sh starts
--------------------------------------------

#!/bin/bash
mount -t iso9660 /dev/cdrom /mountpoint

----------------------------------------------
file ended--------------
another commnad

chmod +x mnt.sh

to make it useful for other users you will have to do one more thing:- set suid to the mnt.sh script check this link for that
http://www.linuxquestions.org/linux/...dia/SUID_HOWTO
 
Old 05-10-2006, 06:34 AM   #4
ashley_31
Member
 
Registered: May 2006
Location: India
Distribution: RedHat Enterprise Linux (Kernel 2.6)
Posts: 42

Original Poster
Rep: Reputation: 15
hey thanks imaineers,,
u always help me out.. i'll try this and let u know.
 
Old 05-10-2006, 06:58 AM   #5
ashley_31
Member
 
Registered: May 2006
Location: India
Distribution: RedHat Enterprise Linux (Kernel 2.6)
Posts: 42

Original Poster
Rep: Reputation: 15
is it better to use an 'alias' command as ----->> alias open mount -t iso9660 /dev/cdrom /mountpoint
for this purpose or should i create a shell script just as u said??
and please tell me the basic difference between the two things.
 
Old 05-10-2006, 11:06 PM   #6
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 116Reputation: 116
You can also set aliases in your .bashrc file. This is where I usually do it. For instance, being an old amiga user, I prefer to copy rather than cp, del rather than rm, and dir rather than ls. So I set these in .bashrc.

Further, I find ps ax | grep commandname to be tedious to enter when I need to get a PID in the task list, so I set an alias called gettask in my .bashrc file to do it for me.

The only downside to this is that I find myself working on computers all over the globe and I either have to copy my .bashrc to whatever machine I am accessing via ssh, or I have to cp and rm and ls except when I am on my home system. Oh well.

Here is my list of aliases that I commonly use:

alias del='rm -dfr'
alias copy='cp'
alias up='cd..'
alias dir='ls -al'
alias dvd='ogle /dev/cdrom1'
alias viewrpm='rpm -qpl'
alias boomer="totem http://asx.abacast.com/boomerradio-cafe-20.asx"
alias gettask="ps ax|grep"
 
Old 05-11-2006, 01:42 AM   #7
imagineers7
Member
 
Registered: Mar 2006
Distribution: BackTrack, RHEL, FC, CentOS, IPCop, Ubuntu, 64Studio, Elive, Dream Linux, Trix Box
Posts: 310

Rep: Reputation: 30
Hi ashley,

Aliases do work faster as they are bash env. variables and are in RAM
but as of with commands we do have more and better control over the script, paths and also every command used in the script.

Security concerns:- If you have a totally customized linux box so that no cracker who has made it to get log in the system would be able to use some commands(such as rm, mv, chattr , passwd, and every sbin cmd) which can mess up things. We can do this by simply renaming the commands, changing the paths and now as everything has differrent names. Our scripts have some names which only the users who are physically there in lab or have told the new commands can use the system. Advantage:-- one added layer of security which still can be overrun.
But what we can do is add more and more layers in such a way that we can sleep without nightmares:java: . Although world is not filled with evils but still if its your job to protect you have to keep up2date with latest weapons!

Last edited by imagineers7; 05-11-2006 at 01:46 AM.
 
Old 05-15-2006, 02:24 AM   #8
ashley_31
Member
 
Registered: May 2006
Location: India
Distribution: RedHat Enterprise Linux (Kernel 2.6)
Posts: 42

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by jiml8
You can also set aliases in your .bashrc file. This is where I usually do it.
Here is my list of aliases that I commonly use:

alias del='rm -dfr'
alias copy='cp'
alias up='cd..'
alias gettask="ps ax|grep"
hey.. i have created alias commands.. But where is this .bashrc file where i have to write them.
I have some files like bash_profiles and bashr and i have even added my alias command in these files but still when i run the command,it says:"command not found."
I have also restarted the computer but still it isnt working.
Please help me out.
 
Old 05-15-2006, 03:22 AM   #9
glvgfz
LQ Newbie
 
Registered: Sep 2005
Location: Sydney, Australia
Distribution: Vector Linux
Posts: 26

Rep: Reputation: 15
Quote:
Originally Posted by ashley_31
hey.. i have created alias commands.. But where is this .bashrc file where i have to write them.
I have some files like bash_profiles and bashr and i have even added my alias command in these files but still when i run the command,it says:"command not found."
I have also restarted the computer but still it isnt working.
Please help me out.
.bashrc should be in your home directory ($HOME/.bashrc or ~/.bashrc). Use "ls -a" to view it as it is considered a hidden file. If you're using an explorer type program to view the system then try check view hidden files.
 
Old 05-15-2006, 03:23 AM   #10
gobi_dgm
Member
 
Registered: Feb 2005
Location: Bangalore
Distribution: FC3
Posts: 137

Rep: Reputation: 15
hi,
.bashrc file will be in your home. if you dont find one, you can create a newone with this name.. it should work after you start the shell again..
 
Old 05-15-2006, 03:32 AM   #11
muha
Member
 
Registered: Nov 2005
Distribution: xubuntu, grml
Posts: 451

Rep: Reputation: 38
You can put .bashrc in your home/<your_user>/ directory. If it's not there create it.
Find it like so with a console:
Code:
ls -al ~/.bashrc
OR
ls -al ~
(by default ls does not list files beginning with a dot (.) so use the -al option to list those).

Test it by sourcing it:
Code:
. .bashrc
Now the aliases you put into .bashrc should work. Test it.

Normally .bashrc is run when you open a console window so you don't have to logout/login linux, just open a new console and that should automatically source (run) your .bashrc
Note: i could be wrong here because the name for .bashrc sometimes differs per system/distro.
I see you are using red hat, maybe update your forum profile to display that you are using red hat?
 
Old 05-15-2006, 04:27 AM   #12
ashley_31
Member
 
Registered: May 2006
Location: India
Distribution: RedHat Enterprise Linux (Kernel 2.6)
Posts: 42

Original Poster
Rep: Reputation: 15
Smile

hey people...
thank u all so much...Its done..
 
  


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
user defined service Tonatiuh Linux - General 2 03-22-2006 02:44 PM
Alias or shell script to confirm 'exit' commands from a shell rose_bud4201 Programming 2 03-08-2006 03:34 PM
how to define user-defined commands in linux mannoulla Linux - General 1 04-05-2005 10:01 PM
how can i run a shell scripts (or a number of commands )when a user logs in to a linu rddreamz Programming 4 05-20-2004 04:08 PM
user defined variables linuxdev Linux - Newbie 4 02-09-2004 01:43 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:28 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration