space-asterisk in bash killed my server

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers space-asterisk in bash killed my server
# 1  
Old 08-28-2009
space-asterisk in bash killed my server

So, here's the deal... I was attempting to type this:

>  grep -R "searchterm" *

and somehow I typed this instead:
>  grep -R "searchterm"

>   *

I accidentally typed "space-asterisk" on the second prompt. This apparently caused Bash to attempt to run the first file in the pwd, which happened to have *something* that spawned a load of processes and killed my server (a VPS with fixed process count). I've never seen this. Can anyone explain the "space-asterisk" phenomenon? It seems like the sort of thing that's a subset of a bigger form of command line trickery and awesomeness, but I can't seem to put together the right search terms to get Dr. Google to explain it to me...
# 2  
Old 08-29-2009
When you execute the command
>  grep -R "searchterm" *

the asterisk is first expanded to all files and (and other items) in the current directory. So for example if the directory contains the files

(and so on)

then the command becomes:
>  grep -R "searchterm" first second third (and so on)

What happened in your case was that the first command failed and then the second command was executed, which expanded to:
 first second third (and so on)

where 'first' is the command and 'second' 'third' are the parameters.

Normally there is a safeguard and 'first' would not be executed since a command is only recognised as a command by the OS if it either is called as <path>/command (e.g. ./first) or it is located in a directory that is part of you search path (the variable "PATH").

My guess would be that there was either:
- a '.' in your search path ( which would illustrate one of the biggest dangers of this practice ), or
- the current directory happened to be in the PATH variable, or
- the name of command happened to be the same as a command in one of the directories in the PATH variable.

For the command to wreak this much havoc you were probably executing the command as root?


Last edited by Scrutinizer; 08-29-2009 at 06:16 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

3 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Print asterisk instead of password (Bash)

OS : RHEL 6.5 Shell : Bash With the following bash shell script, when I enter password, it won't be printed in the screen. But, I would like Asterisk character to be printed instead of the real characters. Any idea how ? $ cat echo "Enter the username" read username echo... (3 Replies)
Discussion started by: John K
3 Replies

2. Shell Programming and Scripting

Use asterisk in shell script bash

Hello, I am trying to save in a file a single "*" but its not working... look what i am doing... FILE="/home/teste/a.txt" ...BEGIN... ASTERISK="*" echo "STRING $ASTERISK STRING" >> $FILE ...END... when i do it, the result is a list of all files of the current... (4 Replies)
Discussion started by: diogooute
4 Replies

3. Shell Programming and Scripting

how to trap unix signal if the process killed/interupt occured in bash...

hey champs, I have a process running.......i have to catch/trap the signal when the process is being interupted/killed (kill -9 pid) option...... how can i achieve the same thru my process........ let my process is and it supposed to take 13 mins to complete, but due to some problem ,... (15 Replies)
Discussion started by: manas_ranjan
15 Replies
Login or Register to Ask a Question