×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

rm alias

rm alias

rm alias

(OP)
hi ,

i want to make alias for rm to be like that :

alias rm 'rm -iv $A | mailx -s "file $A deleted" sherif@hotmail.com'

where A is the input file i will run the rm command on it as example

rm sherif so when that go to the alias it should run like that :

rm -iv $A (where A will bethe input file sherif)  | mailx -s "file $A (where A will bethe input file sherif) deleted" sherif@hotmail.com


in another word i want to make that input file name sherif  to be variable for the alias of the rm command .


hope you can get what i mean , please feed me back how i can make it i need it for emergency thing thanks    

RE: rm alias

Why are you piping the output of the rm command into the email?  Normally rm doesn't display anything.  No harm in doing it though I suppose.

Aliases are not ideal when you need to use parameters in the middle of the command; instead you should try using a function.

Remember also that rm isn't always just used to remove one file, and sometimes people will use options like -rf, so you should use "$@" to include all supplied parameters.

CODE

function rm
{
    rm -iv "$@"
    mailx -s "files $@ deleted" sherif@hotmail.com </dev/null
}

This also assumes that the rm commanded succeeded, which is not necessarily true.

Annihilannic.

RE: rm alias

Quote (Annihilannic):

Normally rm doesn't display anything.

I guess the -v option probably makes it display something...

Annihilannic.

RE: rm alias

(OP)
thanks for your help , i think making alias will not work good ,

just the problem i wanna make alias to send email when ever any one use rm command in my network , wanna monitor  the rm command so do you have any way to do that ?

RE: rm alias

A function, like I suggested... did you try it?

Annihilannic.
tgmlify - code syntax highlighting for your tek-tips posts

RE: rm alias

(OP)
sorry i just see your replay , can feed me back how to use the functions ?

RE: rm alias

What shell are you using?  (i.e. what is the output of ps -fp $$?

Try pasting the example I gave above into your ~/.profile, then log out and log back in again.

Type typeset -f to see what functions you have loaded to make sure it has loaded properly.

Alternatively you can put it in a separate file, for example myfuncs.sh, and then load it like this:

CODE

. ./myfuncs.sh

Annihilannic
tgmlify - code syntax highlighting for your tek-tips posts

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close