Script removes itself


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script removes itself
# 1  
Old 09-08-2006
Script removes itself

I have a script that reads from a file and deletes all files in tha path specified in the file.The problem,however, is the script also deletes itself from the home directory where I run it :-(

Code:
#!/bin/ksh
while read DAYS PURGE_PATH
do
  cd $PURGE_PATH
  find . \( -type d ! -name . -prune  \) -o  -type f -mtime +$DAYS -exec rm {} \;
  cd -
done < xxx.txt

The xxx.txt has this format.

DAYS PURGE_PATH
7 /A/B
....
....
# 2  
Old 09-08-2006
Try to keep scripts out of the paths where you purge files. If you must keep it there, then why not have the script run 'touch' to update the timestamps on itself before it enters the while loop?
# 3  
Old 09-08-2006
followup

How do u mean run "touch"?

Thanks
# 4  
Old 09-08-2006
put
Code:
touch -m scriptfilename

in your script befor rm command.
i guess you are familiar with touch command time format

Last edited by Dhruva; 09-08-2006 at 07:18 AM.. Reason: -t replaced by -m
# 5  
Old 09-08-2006
followup

Hi All,
I think I asked the question wrongly. The point is, the script deletes all the file in the path where I am running it which it shouldnt as the path is not the text file(xxx.txt) where it reads from.

So its not just the script itself that gets deleted, but also the files in the path where the script is located.
# 6  
Old 09-08-2006
cd command may be creating the problem.path in input file is absolute path
if not then try by giving absolute path.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed or awk removes attachment in email

Hi We have a requirement to send email using shell script.email should have html body and pdf attachment. We used uuencode for attaching files and sendmail option to acheive and it is working fine. However custoemr wants to make body of email slightly dynamic. E.g dear customer in html file... (3 Replies)
Discussion started by: Harish7586
3 Replies

2. Shell Programming and Scripting

awk removes delimiter unexpectedly

datafile: blah,blah,blah,blah,blah,blah,blah,blah,blah=0_nblah=0-- ,blah,blah,blah im using the following command to turn the "_n" and "-- " to just a space " " only in the $9th field. meaning, it has to make the changes only in the 9th column/field of the datafile. awk -F, '{... (1 Reply)
Discussion started by: SkySmart
1 Replies

3. UNIX for Dummies Questions & Answers

Why awk removes delimiters?

Code : echo "1,2,3,4"|awk -F "," 'NR==n{$3=a}1' n=1 a=45 Output : 1 2 45 4 Expected : 1,2,45,4 (4 Replies)
Discussion started by: Rajesh_us
4 Replies

4. Shell Programming and Scripting

Newline to space code removes 0 from the first line

I am having a peculiar problem. First I run the code below to append 0 at the start of each line in some hundreds of files that I have in a directory. These files have each word in a newline. for f in *.dat; do echo "0" > tmpfile cat $f >> tmpfile mv tmpfile $f done Then I run this... (7 Replies)
Discussion started by: shoaibjameel123
7 Replies

5. Shell Programming and Scripting

Sed: removes \ from text which causes issues

Hi all, Hoping someone hoping someone might be able to help. i've got the following sed command which i'm using in a bash script that i'm trying to use to insert a new line into an already existing file so i don't have to manually enter it when setting stuff up. the existing script test2/3 are... (3 Replies)
Discussion started by: springs2
3 Replies

6. UNIX for Advanced & Expert Users

perl/sed -i removes link

hello, is it a behavior of or that "-i" removes unix link . example : i create a file "src_file" and link it to "link_file" and then i start "perl -i" the link is removed. does another option exists to change content of a file without temporary files ? UNIX-Version: HP-UX and... (2 Replies)
Discussion started by: bora99
2 Replies

7. Shell Programming and Scripting

Script which removes files from the first directory if there is a file in the second directory

Script must removes files from the first directory if there is a file with same name in the second directory Script passed to the two directories, it lies with them in one directory: sh script_name dir1 dir2 This is my version, but it does not work :wall: set - $2/* for i do set -... (6 Replies)
Discussion started by: SLAMUL
6 Replies

8. Ubuntu

Aptitude removes all packages

Hi Team, Please find below error. I got this after i done something in aptitude. Actually i was trying to update all packages, but unfortunately I removed all packages. Now my server is down. When i boot it gives me me errors of missing .so files. Is there any way to repair my server... (2 Replies)
Discussion started by: paragnehete
2 Replies

9. UNIX for Dummies Questions & Answers

eval removes backslash

Hi, ============= In one of my config files, I have below command eval echo RECORDDELIMITER '\n' The above command results in removing backslash and outputs: RECORDDELIMITER n ============= Any workaround to retain the backslash after eval. Appreciated for your... (10 Replies)
Discussion started by: axes
10 Replies

10. UNIX for Advanced & Expert Users

GAWK removes FS | on output

I have the simple gawk script below. When the script runs in the output of all the ITM lines the FS is replaced with a space, the Non ITM lines retain the | field separator. The ITM lines have many fields and I can't insert "|" between each field because some of the fields are blank. Is... (1 Reply)
Discussion started by: paulr211
1 Replies
Login or Register to Ask a Question