Let me see if I understand what you're doing. You have a script that is given an operand that is the name of the directory to be removed. You expect it to be invoked with something like:
and you have written removeall to be:
And, if the person who invokes removeall forgets to give an operand, bad things happen.
So, why did your script add /*??? If the script had been:
you would get the same results when a directory operand is given, but you wouldn't have a problem when no operand is given (rm would just print a diagnostic saying no operands were given or an empty string is not a valid pathname).
Or your script could actually check for missing or "invalid" operands:
UNIX utilities are there to help you get a job done. If you use them correctly, they can do wonderful things for you. If you tell them to do stupid things, you'll get what you asked for.
One way would be alias rm to a script that checks its parameters:
Edit: as Don Cragun was faster I'll explain how I interpreted the OP: his problem is invoking commands via a third party tool which does not check the parameters it passes.
One way would be alias rm to a script that checks its parameters:
This is an extremely dangerous script. It seems to be intended to catch an attempt to remove all files in and under the root directory. But,it won't complain if you try any of the following (all of which do exactly what this script seems to be intended to catch):
It won't complain if there happen to be any files in the root directory that contain a tab character, start or end with a space character, or contain two or more adjacent space characters. It will fail if any file is added to or removed from the root directory between the time when the rm alias was called and the time when this script processes echo. And, it will attempt to remove a different set of files than what was requested if any files in the operand list contain any whitespace characters.
That's why I explained how I interpreted the original post, but you're right, I was not clear enough.
I assumed that the third party tool issues rm -rf /* if the user of that tool does not provide any arguments. ONLY this case is catched. The user of that tool may not have any knowledge that he is working on an UNIX system at all because he only sees that tools frontend and may not know what effect is caused by not giving any arguments.
For all other cases I'll quote you:
Quote:
Originally Posted by Don Cragun
UNIX utilities are there to help you get a job done. If you use them correctly, they can do wonderful things for you. If you tell them to do stupid things, you'll get what you asked for.
A user who issues the commands you mentioned in the last reply most likely knows what he is doing - that would not be an accidental use of the rm command.
Edit again: thanks for pointing out the issues in your last paragraph.
In my tests (using GNU bash, version 4.1.5(1)-release (x86_64-pc-linux-gnu)) the script compains correctly when there are files in the root directory that contain space or tab characters in their names.
I'm not sure if the race condition can be entirely avoided (given my assumtions about the problem are correct).
The issue with whitespaces in the operand list is caused by my lack of quoting. The last line should read /bin/rm "$@".
I was intended to say as what Cero interpreted.
The tool that I use, would invoke a "rm" or "/usr/bin/rm" commands.
Operands will be passed to the 'rm' utility, with the optional arguments of -r / -rf / -f etc as parameters.
Eg for the parameters:
During any abnormality, there are chances for the tool to send parameters like #folder# or #file# as empty value.
And we know the impact of it.
I was infact trying the options this morning, similar to what cero was describing in.
I created the alias, and it would work in unix terminal, but not in the tool. Not sure, If i need to bounce the tool to refresh the change in .profile.
So with the help of admins, i tried to create the soft link for the rm command.
/usr/bin
And it seems to work for my testing.
And thinking to add more conditions to capture in the script as Don mentioned.
Atleast this way, we can avoid the possibilities of known issues that we far. Hope this would be a right way to proceed.
Last edited by Don Cragun; 06-03-2014 at 04:16 PM..
Reason: Change PHP tags to CODE tags.
If an email is sent from our application server(running on AIX) to an id that is outside of the organization like gmail etc, and if gmail should not treat the mail as spam, what has to be done from unix level? (7 Replies)
Hi,
I've been searching around for solution, hope that some gurus here can help.
I'm using some commands in my shell script and I'd like to protect these command to be moved to another directory. For instance, cp currently in /bin/cp. If I move it to /bin/cpxxx, my script will not be able to... (3 Replies)
Hi,all.Well,I know someone has already asked this question before,however,It's too long before.So i post a new thread here.
Here is the issue.I have a shell script that use awk to calculate something and the script takes about 15 mins,it will use 100% CPU,and the system automatically killed the... (2 Replies)
I understand that on my HP-UX 11.31 system when print queues can no longer communicate with remote printers, the queue disables itself. How can I configure it to stop disabling itself, or alternatively, to re-enable itself when the remote printer comes back online? I have users in warehouses who... (6 Replies)
I have one shell script which is being accessed by many jobs at same time.
I want to make the script such that , other job should wait for the script if script is being used by some other job. Is there any way to implement it in script level ?
Gops (1 Reply)
I am using linux termios structure to configure serial port and read the port by read function. For some reason, if I read the whole buffer, almost every time the buffer does not contain the correct reply message sequence from a device sending reply to my linux PC. So I use... (5 Replies)
Is there anyway to prevent a command from being logged in the history file?
I share a system with others (log in with same account) and I would like to prevent any passwords from being logged in the history file. Some of the commands that I run require username/password on the command line... (7 Replies)
I am using bash shell; my requirement is to run a long command.
Now I have split this long command into a number of shell variables.
Some of these shell variables contain special character ':'
At the end, when the intended long command is executed as a series of small shell variables the ':'... (7 Replies)