Confirm before delete.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Confirm before delete.
# 1  
Old 09-01-2006
Confirm before delete.

I have a script that archive files then delete.How do Its working fine,however,before I perform the delete operation,I want to verify that indeed the FILE is in the path of folder I want to archive.

For example,I have a path /A/B I want all files in B to be archived,the scripts lists all the file then archive them. Now I want to take each file to be deleted,check if the file is in B folder really, then delete it.

Thanks

Code:
#!/bin/ksh

BIN=/interface/backup/dbmig/

age=$1

directory="$2"

[ "$directory" = "" ] && directory=.

cd "$directory" || exit 1

from=`$BIN/today -$age`


cd $BIN
for i in `cat filestoarchive.txt`
do
cd $i
done

find . -mtime 18 | grep -v '.tar$' | $BIN/dttmfilter | awk '$1<="'$from'"{ print;};' |

while read d t f
do
   [ -d $f ] && continue
   opt=u
   [ -w $d.tar ] || opt=c
   tar ${opt}f $d.tar $f && touch -r $f $d.tar && rm -f $f 
done

# 2  
Old 09-05-2006
To check the script we need to know what are these two scripts doing?

It looks like today is returning something
Code:
from=`$BIN/today -$age`

What is dttmfilter?
Code:
$BIN/dttmfilter

# 3  
Old 09-05-2006
followup

$Today is just getting the date of the file. Dont bother about that for now. I think the point is to look,if the file to be removed is present in the path of files to be archived.


The path looks like this.

/A/B/ - means archive all files in B folder then delete,but before I remove any file, check if the file is indeed in B,so that I dont remove some important file that shouldnt be removed-it happened before.

Thanks
# 4  
Old 09-05-2006
I really didn't understand properly anway is that what you want?
Code:
tar ${opt}f $d.tar $f 
 if [ $? -eq 0 ]
  then
  touch -r $f $d.tar 
   if [ -f /A/B/$f ]
   then
   rm -f $f 
   fi
 fi

One more thing abt code.I guess you may want to end this loop at end of the script.
Code:
cd $BIN
for i in `cat filestoarchive.txt`
do
cd $i
done

# 5  
Old 09-05-2006
followup

Why would it necessary to end at the end?Opinions welcome :-) I think you should look at it from here:

Code:
#!/bin/ksh

BIN=/interface/Gunner
cd $BIN
sysMon=`date +%m`
sysDay=`date +%d`
sysYear=`date +%Y`
begDate='0001'
endDate='2359'
X=`./datecalc.sh -a $sysYear $sysMon $sysDay - 53`
Y=`echo $X$begDate|sed 's/ //g'`
Z=`echo $X$endDate|sed 's/ //g'`
touch -t $Y t1
touch -t $Z t2


find ./ -newer t1 \! -newer t2 
while read d t f
do
   [ -d $f ] && continue
   opt=u
   [ -w $d.tar ] || opt=c
   tar ${opt}f $d.tar $f && touch -r $f $d.tar 
   # && rm -f $f
done

I will add your remove code later on. This code seem not to output files created on the same date.

find ./ -newer t1 \! -newer t2 was your idea, but it still output some files from the second day.

Last edited by kayarsenal; 09-05-2006 at 10:28 AM.. Reason: error
# 6  
Old 09-05-2006
You can use this tar option

tar --remove-files -zcvf

to archive and delete in one command
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to confirm that I've reached the nproc limit?

Hi, I am getting the error su: cannot set user id: Resource temporarily unavailable. In limits.conf, it shows soft nproc 2047 for this user. ps H -u | wc -l shows 508 processes only. Linux flavour is Red Hat Enterprise Linux Server release 5.10 (Tikanga) Any advice will be much... (1 Reply)
Discussion started by: newbie_01
1 Replies

2. AIX

Need to confirm something regarding TL upgrades

Hi everyone, My current AIX OS level is "7100-01-06-1241" and I am planning to upgrade it to " 7100-02-03 ". Can i directly upgrade it to "7100-02-03" from 7100-01-06" ? or first i need to upgrade the "7100-01-06" LPAR to TL 02 and then reboot and then upgrade it to TL 02 SP03 ? ... (4 Replies)
Discussion started by: System Admin 77
4 Replies

3. Solaris

Reboot required on Server, Just confirm my settings.

Hi Guys, I need to reboot one Server as the newly inserted disk is not getting detected in system , I have also confirmed with Sun Support and finally it was the reboot which was required after doing all troubleshooting stuff. So I have disassembled the mirror and kept working disk's single... (3 Replies)
Discussion started by: manalisharmabe
3 Replies

4. Shell Programming and Scripting

Confirm file copy

Need to check whether the source file(FTP'ed file) is completly copied or not such that I can further action on the same. I have created the below script to achieve this by checking for every 10secs to whether file size is same or not but it may create a problem if the file transfer is slow and if... (4 Replies)
Discussion started by: palanisvr
4 Replies

5. Shell Programming and Scripting

sed - How to confirm substitution

How to confirm whether a particular substitution taken place or not ? Find the code below :- #!/bin/ksh COUNT=0 ####### Create backup of the original file ###### cp passwd passwd_old ####### Read the csv file for unixid and project ###### while IFS=, read unix_id project_id do ... (1 Reply)
Discussion started by: hiten.r.chauhan
1 Replies

6. Shell Programming and Scripting

Script to Reboot and Confirm

On my Solaris box I have to reboot some devices like below. However I think this can be done through a script. I've create a list that contains the devices IP addresses. Here's the logic: Reboot 4 devices and sleep for 5mins(300s.) While the devices are rebooting, I would like to confirm... (9 Replies)
Discussion started by: ravzter
9 Replies

7. Solaris

Confirm the location of the bootblk kernel

Dear All i am new to solaris. I am using solaris 5.10 running on my sun blade 150 (sparc). Nowadays i studying about boot process and i am bit confused with the location of the kernel,bootblk. As i found through the internet, The location of the kernel is ... (0 Replies)
Discussion started by: kingston
0 Replies

8. Solaris

How can we confirm that, the disk has failed in Solaris?

Hi All, Seems to be one of the disk has failed on my Solaris server. How do i confirm that disk has really failed or not? Here are alert details. ------- iostat -En out/put c1t3d0 Soft Errors: 1884 Hard Errors: 153 Transport Errors: 54 Vendor: FUJITSU Product:... (3 Replies)
Discussion started by: Naresh Kommina
3 Replies

9. UNIX for Dummies Questions & Answers

Confirm job execution

Hello everybody, Can anybody tell me how do we comfirm the execution of a scheduled job ? In other words, how do I know whether my scheduled script is being executed or not ? Thanks Jitu JK (2 Replies)
Discussion started by: jitu.jk
2 Replies

10. Forum Support Area for Unregistered Users & Account Problems

new account, not recieving email to confirm

Hello, I registered an account several hours ago, and never recieved the email registration link in my email account. Read the instructions posted here, and requested to resend registration link, and this one also has not shown up in my email acccount. yes, I've checked the bulk folder as... (1 Reply)
Discussion started by: denn
1 Replies
Login or Register to Ask a Question