|
Home > Archive > Unix administration > November 2004 > script which removed a directory unknowingly
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
script which removed a directory unknowingly
|
|
| yls177 2004-11-23, 2:53 am |
| I have a script which for no reasons i know of remove a directory
named "log" which is in /unix/outgoing/esap/ . Only 2 commands that i
know of which does this, rm and mv.
# more myscript| grep -i mv
[ "${RESULT:=null}" != 'null' ] && mv $FILE ${S_DIR}.moved && \
# more myscript| grep -i rm
find /unix/outgoing/fsap/log -name "myfile*" -mtime +7 -exec rm {} \;
find /unix/outgoing/esap/log-name "myfile*" -mtime +7 -exec rm {} \;
find /unix/outgoing/esap.moved/log -name "myfile*" -mtime +7 -exec rm
{} \;
find ${S_DIR}.moved -name "*" -mtime +7 -exec rm {} \;
S_DIR='/unix/outgoing/esap'
1) will the above statements removed my "log" directory in
/unix/outgoing/esap/?
2) In [ "${RESULT:=null}" != 'null' ] && mv $FILE ${S_DIR}.moved && \,
both FILE, RESULT, S_DIR are variabbles, but basically, what is it
moving?
| |
| Laurenz Albe 2004-11-23, 8:27 am |
| yls177 <yls177@hotmail.com> wrote:
> I have a script which for no reasons i know of remove a directory
> named "log" which is in /unix/outgoing/esap/ . Only 2 commands that i
> know of which does this, rm and mv.
>
> # more myscript| grep -i mv
> [ "${RESULT:=null}" != 'null' ] && mv $FILE ${S_DIR}.moved && \
> # more myscript| grep -i rm
> find /unix/outgoing/fsap/log -name "myfile*" -mtime +7 -exec rm {} \;
> find /unix/outgoing/esap/log-name "myfile*" -mtime +7 -exec rm {} \;
> find /unix/outgoing/esap.moved/log -name "myfile*" -mtime +7 -exec rm
> {} \;
> find ${S_DIR}.moved -name "*" -mtime +7 -exec rm {} \;
>
> S_DIR='/unix/outgoing/esap'
>
>
> 1) will the above statements removed my "log" directory in
> /unix/outgoing/esap/?
>
> 2) In [ "${RESULT:=null}" != 'null' ] && mv $FILE ${S_DIR}.moved && \,
> both FILE, RESULT, S_DIR are variabbles, but basically, what is it
> moving?
Before I try to answer, a few suggestions:
- Choosing a newsgroup that matches your problem better will give you
better answers.
- When asking questions about shell scripts, always say which shell
and what version you are using. Also, since 'find' comes into play,
the version of 'find' you use might be interesting, too.
- Read the manual pages of your shell and of 'find' to understand what
is going on - this is always better than asking. Find out what
the [ ], the &&, the ${...} and the ${VAR:=default} actually do.
- If you want to trace the commands that the shell is actually
executing, insert a 'set -x' immediately above the interesting code
segment and a 'set +x' immediately after it. Run the script.
You will see what is going on!
Now for your questions:
ad 2):
That depends entirely on the contents of the variables.
If RESULT is unset or set to "null", nothing will be moved at all.
Otherwise the file whose name is contained in the FILE variable will
be moved to the content of the S_DIR variable with .moved appended.
ad 1):
The only command that can remove '/unix/outgoing/esap/log' is the
'mv $FILE ${S_DIR}.moved'. But only if the variable FILE contains
"/unix/outgoing/esap/log".
In that case it will be moved to wherever ${S_DIR}.moved points to.
None of the three 'find' commands will consider the directory,
moreover you cannot remove a directory with 'rm' (without -r).
My post is already lenghty, but I cannot help mentioning that there
is an infinite magnitude of commands that will remove a directory.
Every command that is not a builtin or a function will execute an
executable (or shell script), and what tells you that none of these
on your system will remove the dirctory in question?
Read the script and understand what it does.
Yours,
Laurenz Albe
| |
| yls177 2004-11-24, 8:48 pm |
| Laurenz Albe <albe@culturallNOSPAM.com> wrote in message news:<cnvdih$35g$1@at-vie-newsmaster01.nextra.at>...
> yls177 <yls177@hotmail.com> wrote:
>
> Before I try to answer, a few suggestions:
> - Choosing a newsgroup that matches your problem better will give you
> better answers.
> - When asking questions about shell scripts, always say which shell
> and what version you are using. Also, since 'find' comes into play,
> the version of 'find' you use might be interesting, too.
> - Read the manual pages of your shell and of 'find' to understand what
> is going on - this is always better than asking. Find out what
> the [ ], the &&, the ${...} and the ${VAR:=default} actually do.
> - If you want to trace the commands that the shell is actually
> executing, insert a 'set -x' immediately above the interesting code
> segment and a 'set +x' immediately after it. Run the script.
> You will see what is going on!
>
> Now for your questions:
>
> ad 2):
> That depends entirely on the contents of the variables.
> If RESULT is unset or set to "null", nothing will be moved at all.
> Otherwise the file whose name is contained in the FILE variable will
> be moved to the content of the S_DIR variable with .moved appended.
>
RESULT will contain a value from "grep -i "transfer completed"
ftp.log
All my files have been transferred successfully, except that the
directory log is always removed as well. Please advised.
> ad 1):
> The only command that can remove '/unix/outgoing/esap/log' is the
> 'mv $FILE ${S_DIR}.moved'. But only if the variable FILE contains
> "/unix/outgoing/esap/log".
> In that case it will be moved to wherever ${S_DIR}.moved points to.
this is part of my script which is in the corresponding area
"
S_DIR='/unix/outgoing/esap'
cd $S_DIR
ls|while read FILE; do
[ "${RESULT:=null}" != 'null' ] && mv $FILE ${S_DIR}.moved && \
g/${FTP_HOST}.log) && \
done
"
I think this is it. variable FILE is the name of a file in S_DIR. And
directory log is in S_DIR.
S_DIR='/unix/outgoing/esap'
directory log is in /unix/outgoing/esap/log
therefore, directory log is read in the statement "while read FILE" ?
>
> None of the three 'find' commands will consider the directory,
> moreover you cannot remove a directory with 'rm' (without -r).
>
> My post is already lenghty, but I cannot help mentioning that there
> is an infinite magnitude of commands that will remove a directory.
> Every command that is not a builtin or a function will execute an
> executable (or shell script), and what tells you that none of these
> on your system will remove the dirctory in question?
> Read the script and understand what it does.
>
> Yours,
> Laurenz Albe
| |
| Bill Marcum 2004-11-25, 2:50 am |
| On 24 Nov 2004 18:41:52 -0800, yls177
<yls177@hotmail.com> wrote:
>
>
> I think this is it. variable FILE is the name of a file in S_DIR. And
> directory log is in S_DIR.
>
> S_DIR='/unix/outgoing/esap'
> directory log is in /unix/outgoing/esap/log
>
> therefore, directory log is read in the statement "while read FILE" ?
>
>
Then the log should now be in ${S_DIR}.moved, is it?
--
"At a scheduled time, the robot would pull the flush lever and scream as
it got sucked down the drain." --Kibo
| |
| Laurenz Albe 2004-11-25, 7:50 am |
| yls177 <yls177@hotmail.com> wrote:
You quoted my post, but you did not read that, did you?
[vbcol=seagreen]
>
> RESULT will contain a value from "grep -i "transfer completed"
> ftp.log
>
> All my files have been transferred successfully, except that the
> directory log is always removed as well. Please advised.
How shall I advise you? You didn't tell me what is in RESULT.
But it is not important now as your question seems to be answered below:
> this is part of my script which is in the corresponding area
> S_DIR='/unix/outgoing/esap'
>
> cd $S_DIR
>
> ls|while read FILE; do
>
> [ "${RESULT:=null}" != 'null' ] && mv $FILE ${S_DIR}.moved && \
> g/${FTP_HOST}.log) && \
>
> done
> I think this is it. variable FILE is the name of a file in S_DIR. And
> directory log is in S_DIR.
>
> S_DIR='/unix/outgoing/esap'
> directory log is in /unix/outgoing/esap/log
>
> therefore, directory log is read in the statement "while read FILE" ?
Yes, and you will presumably find it moved to /unix/outgoing/esap.moved
I say 'presumably' as the statement "g/${FTP_HOST}.log)" leaves me
completely clueless - I refuse to believe that this can be a valid
statement, although I still have no clue as to what shell you are using.
Yours,
Laurenz Albe
| |
| Chris F.A. Johnson 2004-11-25, 7:50 am |
| On Tue, 23 Nov 2004 at 08:01 GMT, yls177 wrote:
> I have a script which for no reasons i know of remove a directory
> named "log" which is in /unix/outgoing/esap/ . Only 2 commands that i
> know of which does this, rm and mv.
>
> # more myscript| grep -i mv
> [ "${RESULT:=null}" != 'null' ] && mv $FILE ${S_DIR}.moved && \
> # more myscript| grep -i rm
> find /unix/outgoing/fsap/log -name "myfile*" -mtime +7 -exec rm {} \;
> find /unix/outgoing/esap/log-name "myfile*" -mtime +7 -exec rm {} \;
> find /unix/outgoing/esap.moved/log -name "myfile*" -mtime +7 -exec rm
> {} \;
> find ${S_DIR}.moved -name "*" -mtime +7 -exec rm {} \;
>
> S_DIR='/unix/outgoing/esap'
>
>
> 1) will the above statements removed my "log" directory in
> /unix/outgoing/esap/?
>
> 2) In [ "${RESULT:=null}" != 'null' ] && mv $FILE ${S_DIR}.moved && \,
> both FILE, RESULT, S_DIR are variabbles, but basically, what is it
> moving?
First, post the script, not lines taken out of context.
Second, make sure that lines do not wrap, or the script may be
impossible to decipher.
Third, have you tried using "set -x" to see what the script is
doing?
--
Chris F.A. Johnson http://cfaj.freeshell.org/shell
========================================
===========================
My code (if any) in this post is copyright 2004, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License
|
|
|
|
|