Issues with setting Aliases


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Issues with setting Aliases
# 22  
Old 02-09-2016
While fully seconding what all the others are reasoning about: did you consider defining a shell function rm in which you could do what you want to "customize" the command?
# 23  
Old 02-09-2016
\rm escapes an alias and a function.
Or is there an assumption that a stupid user cannot type a \ character?
# 24  
Old 02-09-2016
Hi mohtashims,
I agree with everything bakunin, RudiC, and MadeInGermany said.

An alias won't keep users from invoking /bin/rm -f .... A shell function won't keep users from invoking /bin/rm -f ....

But, of course, there is something you can do. Replace /bin/rm with your own version of rm that generates an error message whenever anyone tries to use the -f option. You will get exactly what you want. System maintenance procedures may stop working. System boot procedures may stop working. User shell scripts may stop working. So what; you have made sure that no user is able to avoid an error message when removing a temp file that might not have been created in the first place. Why should they want to do that when they can rewrite their scripts so they will work on your perfected operating system even through their scripts work perfectly on every other POSIX-conforming system in the world.

After modifying rm, are you going to rewrite the manual pages for rm and any utility on your system that might invoke rm with a -f option as well? Or, do you just plan to tell your users that the implementation-supplied man pages are broken and that you have "fixed" the system to work more safely? If third-party software doesn't work on your system because you have fixed rm, are you going to tell those third-party suppliers to "fix" their code to work on your system; or are you going to tell users that they just shouldn't buy from those suppliers because the programmers who wrote their code used an option that you have decided is too dangerous to be allowed to be used on your "improved" system.

And, if a user wants to remove a read-only file from your system, obviously users on your system should learn to use the much safer sequence of commands:
Code:
chmod 644 file
/bin/rm file

instead of the dangerous code:
Code:
rm -f file

After all, typing two or three times as much isn't much more likely to introduce typographic errors is it? And, running two utilities instead of one and accessing a file twice instead of once won't affect system performance, will it?

Or, maybe you want your version of /bin/rm to always behave as if the -i option is in effect. Of course, if you do that, you won't be able to remove any files in a non-interactive script anymore, but so what? Why should anybody be allowed to remove any file without interactively confirming that they really wanted to remove those files? After all, there is no reason why anyone should be allowed to run a cron job that removes temporary files it uses, is there?

And, what about the yes utility? Are you going to remove it to so users can't use:
Code:
yes|rm -i /dir/* > /dev/null

(which they will quickly learn to do since the -f option is no longer available). And, after you remove the yes utility, are you going to fix all of the shells on your system so your users can't use a while loop with echo or printf to simulate the yes utility? Are you going to get rid of the C and C++ compilers so users can't write their own rm utilities and their own yes utilities? And, are you going to remove the chmod, find, rmdir, and unlink utilities from your system so they can't replace:
Code:
rm -rf file...

with the MUCH less efficient:
Code:
find file... ! -type d -exec chmod 600 {} \; -exec unlink {} \;
find file... -type d -depth -exsec chmod 600 {} \; -exec rmdir {} +

? After all, UNIX, Linux, and BSD systems are known for providing lots of ways to do some pretty common things (like remove a file).

If you could fix alias to work the way you want it to, would you remove unalias from all of the shells on your system so users can't get rid of your fix? And, would you fix alias to that an alias for rm can't be redefined?

If you treat your users like foolish children who can't be trusted to use standard operating system features, you will quickly learn that foolish children can turn into rebellious teenagers. And those rebellious teenagers will find ways to get around your restrictions until they are able to move out of your realm of control and work on an unmodified system where they can do their jobs without having to work around your "system improvements". (And don't think that your foolish and rebellious children won't talk to each other and pass around ways to get around your restrictions.)

So, yes, there are lots of things you can try to disable the rm -f option. But, you can't keep users from getting around anything you do. And, you can't keep users from accidentally removing a file (or thousands of files) if they aren't careful typing commands into a shell and when they are responding to prompts issued by every utility they invoke.

You will eventually find out that if you modify your system to become foolproof, a new breed of fool will start using your system.
These 2 Users Gave Thanks to Don Cragun For This Post:
# 25  
Old 02-09-2016
So true Don, I went once long ago through that sort of bad experience... its not rm but cp I had to rewrite (not my idea but I was the system analyst at the time and was asked by IT director...) the idea was it checked how many copies on the system and allow developpers to only have 5 as we were short regularly of disk space... I lived a true nightmare as I awakened the monkey's curiosity in them... It taught me UNIX was in someway beautifully simple and to work as it does, has to stay "simple" and standard to the way it was designed... I then changed attitude altogether, I educated the staffl, show people what/how to and treat them as grown up, the more they know the less trouble/work you have later...
This User Gave Thanks to vbe For This Post:
# 26  
Old 02-09-2016
Linux

I couldn't stop laughing reading the last few comments and I get the point that it is not feasible to impose the default behaviour of the commands.

Anyways ... can you help me with few commands with flags as examples that override each other like -f overrides -i for rm command ?

Last edited by mohtashims; 02-09-2016 at 10:14 AM..
# 27  
Old 02-09-2016
Quote:
Originally Posted by mohtashims
I couldn't stop laughing reading the last few comments and I get the point that it is not feasible to impose the default behaviour of the commands.

Anyways ... can you help me with few commands with flags as examples that override each other like -f overrides -i for rm command ?
I'm very happy to hear that you were laughing. That means you'll remember this discussion. Smilie

It is common practice any time a utility has mutually exclusive behaviors specified by a pair of options to use the behavior specified by the last one of those options found on the command line. But as always, there are exceptions. The standards seldom explicitly state that the last mutually exclusive option "shall be used" and instead state that the default behavior is undefined if a user specifies more than one mutually exclusive option unless the description of that utility explicitly overrides the default. One case where the standard always specifies that the last one shall be used is the -H, -L, and -P options that appear on many utilities that process symbolic links (such as cd, chgrp, chmod, chown, cp, etc.). In all of these cases the last specified option of these three is required to be used and any previous occurrences of these three options must be ignored by the system (just like the -f and -i rm options we have been discussing in this thread).
This User Gave Thanks to Don Cragun For This Post:
# 28  
Old 02-10-2016
Quote:
Originally Posted by Don Cragun
I'm very happy to hear that you were laughing. That means you'll remember this discussion. Smilie

It is common practice any time a utility has mutually exclusive behaviors specified by a pair of options to use the behavior specified by the last one of those options found on the command line. But as always, there are exceptions. The standards seldom explicitly state that the last mutually exclusive option "shall be used" and instead state that the default behavior is undefined if a user specifies more than one mutually exclusive option unless the description of that utility explicitly overrides the default. One case where the standard always specifies that the last one shall be used is the -H, -L, and -P options that appear on many utilities that process symbolic links (such as cd, chgrp, chmod, chown, cp, etc.). In all of these cases the last specified option of these three is required to be used and any previous occurrences of these three options must be ignored by the system (just like the -f and -i rm options we have been discussing in this thread).
Although i need to study and understand this i did try the cp command and it works like you said.

Code:
bash-4.3$ cd /tmp                                                                                                                                             
bash-4.3$ ls -ltr                                                                                                                                             
total 0                                                                                                                                                       
drwxr-xr-x 3 19912 19912 16 Feb 10 01:35 Hello                                                                                                                
lrwxrwxrwx 1 19912 19912 17 Feb 10 01:36 logs -> Hello/www/output/
bash-4.3$ cd -PL logs                                                                                                                                         
bash-4.3$ pwd                                                                                                                                                 
/tmp/logs 
bash-4.3$ cd /tmp
bash-4.3$ cd -LP logs                                                                                                                                         
bash-4.3$ pwd                                                                                                                                                 
/tmp/Hello/www/output

Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Proxy Server

Samba on AIX, issues setting read-only flag on files?

Hello, I am having issues setting the "read-only" flag via Windows Explorer on my AIX Samba share... I have on my AIX 7.1 system installed Samba 3.6.24 and configured, joined to our Windows domain successfully. The samba binaries I got from perzl.org/aix In my smb.conf I have... ... (1 Reply)
Discussion started by: c3rb3rus
1 Replies

2. Solaris

Is there a difference between setting a user as nologin and setting it as a role?

Trying to figure out the best method of security for oracle user accounts. In Solaris 10 they are set as regular users but have nologin set forcing the dev's to login as themselves and then su to the oracle users. In Solaris11 we have the option of making it a role because RBAC is enabled but... (1 Reply)
Discussion started by: os2mac
1 Replies

3. UNIX for Advanced & Expert Users

Issues in setting up remote syslogging

Hello, I am using Ubuntu Linux and having problems in setting up remote syslogging. Appreciate your help on this. On the server unix host, I have made following changes. uncommented following lines in /etc/rsyslog.conf $ModLoad imudp $UDPServerRun 514 Now i am trying to run rsyslog in... (0 Replies)
Discussion started by: ravi.videla
0 Replies

4. Solaris

Help with beginner issues setting up ZFS??

Hi, I'm new to Solaris 11. The goal is to set up a ZFS raid-Z2 NAS. These are the instructions I've been trying to follow, with no luck: "Setting Up an OpenSolaris NAS Box: Father-Son Bonding" (not allowed to post URL) Issues: 1) Root access is evidently required but I don't... (8 Replies)
Discussion started by: lakedude
8 Replies

5. UNIX for Dummies Questions & Answers

Setting aliases

How come if I set an alias as such: alias dt 'date "+%Y-%m-%d %H:%M:%S"' it will work as intended, ie the command 'dt' does prompt the date and time, but not when invoked through a script as such: #!/bin/sh alias dt 'date "+%Y-%m-%d %H:%M:%S"' The OS is FreeBSD 7.1. Thanks in advance (4 Replies)
Discussion started by: figaro
4 Replies

6. Shell Programming and Scripting

etc aliases

Hello: i have several server with own etc aliases. right now i want to combine it all into a general etc aliases in a new freebsd server. cause it consist hundred thousand of record user inside how to make a shell script to combine it or configure it. all etc aliases record example: ... (0 Replies)
Discussion started by: peterLfs
0 Replies

7. UNIX for Dummies Questions & Answers

aliases

Is there a way to view what aliases are running on a given session? (1 Reply)
Discussion started by: BG_JrAdmin
1 Replies

8. Programming

aliases

Hi. I have a C program that is using the **environ pointer and I am trying to set up aliases for a system("/bin/ksh") call. This works for other environment variables but not for the aliases. Does anyone know if this can be done? Thanks ahead of time. (1 Reply)
Discussion started by: mluey61
1 Replies
Login or Register to Ask a Question