Menu for Purge


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Menu for Purge
# 1  
Old 02-11-2014
Menu for Purge

I have these commands that help me find and delete files over certain days.

How can I build a menu to list the files, and then hit y for yes to delete or no?

Code:
find /logs/212/abinitio/prod/mfs/partitions/part0/mfs_12way_001/mfs_12way/sncrpt/main/ -name "*dat" -mtime +1 -exec ls -ltr {} \;
find /cddata/bi/logs/212/data/cdr/ -name "*dat" -mtime 10 -exec ls -ltr {} \;
find /logs/212/data/cem/ -name "*dat" -mtime 10 -exec ls -ltr {} \;

find /logs/212/abinitio/prod/mfs/partitions/part0/mfs_12way_001/mfs_12way/sncrpt/main/ -name "*dat" -mtime +1 -exec rm -rf {} \;
find /cddata/bi/logs/212/data/cdr/ -name "*dat" -mtime 10 -exec rm -rf {} \;
find /logs/212/data/cem/ -name "*dat" -mtime 10 -exec rm -rf {} \;


Last edited by Don Cragun; 02-11-2014 at 05:49 PM.. Reason: Add CODE tags.
# 2  
Old 02-11-2014
You don't need to create a menu. If you change:
Code:
-exec rm -rf {} \;

to
Code:
-ok rm -rf {} \;

find will show you the rm command it is ready to execute and ask you whether to run it or skip it for each selected file. Alternatively, you could use:
Code:
-exec rm -ri {} +

to have rm do the prompting and have find run rm fewer times.
# 3  
Old 02-11-2014
and then I need to log the files deleted as well.

---------- Post updated at 03:02 PM ---------- Previous update was at 03:00 PM ----------

Well I have about 25 more directories and with different -mtimes so I was going to make a menu so that we could go through all of them one at a time, verify visually before we delete them?

---------- Post updated at 03:03 PM ---------- Previous update was at 03:02 PM ----------

I also don't want them to ask Y or N for each file but for each dir.

Last edited by xgringo; 02-11-2014 at 06:21 PM..
# 4  
Old 02-11-2014
Code:
ask() { # "Question to ask"
# Ask a question (y/n)
# Returns 0 for yes, 1 for no
    read -n1 -p "$1 (y/n): " ANSWER
    [ [yjso] = "$ANSWER" ] && return 0 || return 1
    # Returns YES (0) for yes, si, oui, ja (first letters)
}

BASE=/some/dir
cd $BASE

for FOUND in $(find . -name);do     ### might become ARG_MAX, but you said its only ~25
    [ -d $FOUND ] && \
       ask "Delete: $FOUND and all subdirectories?" && \
       rm -fr $FOUND
done

Hth & gn8
Do on your own risk - untested too tired on windows...
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Gnome 3.28.3 menu item dissapears under the system menu

I installed CentOS 8 with Gnome 3.28.2 and I noticed that the "switch user" menu item disappeared from under the system menu of Gnome classic (Both X11 & Wayland). I checked google and this problem seems to have a history going back several releases of Gnome. Unfortunately, I never found a... (1 Reply)
Discussion started by: bodisha
1 Replies

2. Shell Programming and Scripting

Need help in create menu with 3 sub menu using the case command

hi all i am a newbie to this is there any examples on creating a main menu with 3 sub menu main menu -> option a , b and c a menu -> option 1 ,2 and 3 b menu -> option 1 ,2 c menu -> option 1 ,2 i am getting headache as my code kept getting unexpected EOF ---------- Post... (0 Replies)
Discussion started by: chercm
0 Replies

3. Emergency UNIX and Linux Support

Purge in oracle9i

From morning we are facing some issues in tablespaces in oracle9i. Tried deleting some huge records... but even thought it is still giving tablespcases in full. Then i tried and googling ... found we need to purge recyclebin of oracle.. but thats not woking in oracle9i... can any one... (1 Reply)
Discussion started by: greenworld123
1 Replies

4. UNIX for Advanced & Expert Users

Purge MAil file

Hi, merry christmas. on AIX 6.1, the file /var/spool/mail/user, should/can be purged manually ? Any commande line to purge it ? Thanks. (2 Replies)
Discussion started by: big123456
2 Replies

5. Shell Programming and Scripting

Menu in Menu script issue

Problem: I am trying to create a menu in a menu script and I am running into an issue with the calculator portion of the script. I am first presented with the ==Options Menu== which all 5 options working correctly. Now comes the fun part. I select option 1 which takes me to my ==Calculator... (1 Reply)
Discussion started by: iDdraig
1 Replies

6. Shell Programming and Scripting

script to archive and purge

Hi, I am writing a shell script for archive data from a table. The design is as follows. Step 1: Execute the select query and extract the data into a text file. Step 2: The primary key for this table is TRACKING_NUM, TRACKING_NUM_SUFFIX, TIMESTAMP_UPDATED. So These three fields will be read... (1 Reply)
Discussion started by: kmanivan82
1 Replies

7. Shell Programming and Scripting

script for purge

Hi , I want to purge 7 days older data from a list of data sorted on date in a log file... Can anyone provide me with the shell script for the same.. Thanks, Jaz (1 Reply)
Discussion started by: JP003
1 Replies

8. UNIX for Dummies Questions & Answers

purge xterm

Being new I had my focus in the wrong place and typed in xterm instead of <If you can't guess, good>. Can I purge xterm so that this word no longer appears using up or down arrows? (1 Reply)
Discussion started by: noobie_doo
1 Replies
Login or Register to Ask a Question

Featured Tech Videos