Sponsored Content
Top Forums Shell Programming and Scripting shell script to partial delete Post 302330678 by q8devilish on Thursday 2nd of July 2009 03:54:59 AM
Old 07-02-2009
shell script to partial delete

guys i need some help in writing a shell script, what i am trying to write is a shell script that can delete generated trace files my software usually generated everyday, i will give an example to make it easy to understand
Code:
root@cms-db # pwd
/pcard17/trace
root@cms-db # ls -l HSM_VERIF.TRC*
-rw-r--r--   1 pwrcard  dba      4194432 Jul  1 00:18 HSM_VERIF.TRC111111545
-rw-r--r--   1 pwrcard  dba      4194432 Jul  1 00:51 HSM_VERIF.TRC111111546
-rw-r--r--   1 pwrcard  dba      4195092 Jul  1 01:29 HSM_VERIF.TRC111111547
-rw-r--r--   1 pwrcard  dba      4194432 Jul  1 02:22 HSM_VERIF.TRC111111548
-rw-r--r--   1 pwrcard  dba      4195092 Jul  1 04:02 HSM_VERIF.TRC111111549
-rw-r--r--   1 pwrcard  dba      4194432 Jul  1 05:33 HSM_VERIF.TRC111111550
-rw-r--r--   1 pwrcard  dba      4194432 Jul  2 06:16 HSM_VERIF.TRC111111551
-rw-r--r--   1 pwrcard  dba      4194432 Jul  2 06:40 HSM_VERIF.TRC111111552
-rw-r--r--   1 pwrcard  dba      4194432 Jul  2 06:58 HSM_VERIF.TRC111111553
-rw-r--r--   1 pwrcard  dba      4194432 Jul  2 07:15 HSM_VERIF.TRC111111554
-rw-r--r--   1 pwrcard  dba      4195752 Jul  2 07:34 HSM_VERIF.TRC111111555
-rw-r--r--   1 pwrcard  dba      4195488 Jul  2 07:52 HSM_VERIF.TRC111111556
-rw-r--r--   1 pwrcard  dba      4194432 Jul  2 08:04 HSM_VERIF.TRC111111557
-rw-r--r--   1 pwrcard  dba      4195224 Jul  2 08:16 HSM_VERIF.TRC111111558
-rw-r--r--   1 pwrcard  dba      4194432 Jul  2 08:27 HSM_VERIF.TRC111111559
-rw-r--r--   1 pwrcard  dba      4195224 Jul  2 08:37 HSM_VERIF.TRC111111560
-rw-r--r--   1 pwrcard  dba      4195620 Jul  2 08:45 HSM_VERIF.TRC111111561
-rw-r--r--   1 pwrcard  dba      4194432 Jul  2 08:57 HSM_VERIF.TRC111111562
-rw-r--r--   1 pwrcard  dba      4194828 Jul  2 09:06 HSM_VERIF.TRC111111563
-rw-r--r--   1 pwrcard  dba      4195356 Jul  2 09:13 HSM_VERIF.TRC111111564
-rw-r--r--   1 pwrcard  dba      4194696 Jul  2 09:20 HSM_VERIF.TRC111111565
-rw-r--r--   1 pwrcard  dba      4194432 Jul  2 09:28 HSM_VERIF.TRC111111566
-rw-r--r--   1 pwrcard  dba      4194432 Jul  2 09:36 HSM_VERIF.TRC111111567
-rw-r--r--   1 pwrcard  dba      4194432 Jul  2 09:43 HSM_VERIF.TRC111111568
-rw-r--r--   1 pwrcard  dba      4194432 Jul  2 09:50 HSM_VERIF.TRC111111569
-rw-r--r--   1 pwrcard  dba      4195092 Jul  2 09:56 HSM_VERIF.TRC111111570
-rw-r--r--   1 pwrcard  dba      4194564 Jul  2 10:04 HSM_VERIF.TRC111111571
-rw-r--r--   1 pwrcard  dba      4194432 Jul  2 10:11 HSM_VERIF.TRC111111572
-rw-r--r--   1 pwrcard  dba      4195092 Jul  2 10:17 HSM_VERIF.TRC111111573
-rw-r--r--   1 pwrcard  dba      4194432 Jul  2 10:23 HSM_VERIF.TRC111111574
-rw-r--r--   1 pwrcard  dba      4194828 Jul  2 10:29 HSM_VERIF.TRC111111575
-rw-r--r--   1 pwrcard  dba      4194432 Jul  2 10:34 HSM_VERIF.TRC111111576
-rw-r--r--   1 pwrcard  dba       886908 Jul  2 10:36 HSM_VERIF.TRC111111577

what i am trying to do is crating a script that will delete only yesterday files and keep only latest 2 files for security reasons.

my attempt in creating was like that to delete all yesterday file
Code:
#!/bin/bash
clear
echo "Please Enter YESTERDAYS Date in this order Mmm dd"
echo -n "Enter Date:"
read otaibi
ls -l /pcard17/trace | grep "$otaibi" | grep HSM_VERIF.* | nawk '{print $9}' > /pcard17/trace/delete.txt
clear
cd /pcard17/trace
cat /pcard17/trace/delete.txt | while read line; do rm "$line" ; done

now how can i delete yesterday files and keep latest 2 files?
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

shell script to delete directories...

Hi. I'm trying to write a script that will delete all directories found, that are not named as a "number" (year)... here is what i mean, let's say i have within /data/exports the following directories: /data/exports/2000 /data/exports/2001 /data/exports/2002 /data/exports/daily/2000... (5 Replies)
Discussion started by: Stephan
5 Replies

2. Shell Programming and Scripting

shell script for delete old files

i want to delete all the files in my directory except the latest one. i need to do this from shell script. say i have a.txt - latest file b.txt, c.txt.. it should delete all the files except a.txt? (4 Replies)
Discussion started by: krishnarao
4 Replies

3. UNIX for Advanced & Expert Users

delete line from file if successful partial string found

Id like to delete a line from a file using (preferably a single line unix command) if it contains a certain string pattern. If line contains "abcdef" then delete that line. Help greatly appreciated. (7 Replies)
Discussion started by: cronjob78
7 Replies

4. Shell Programming and Scripting

Partial Delete Lines

Hi, Need to delete line prior to (INSERT/UPDATE/DELETE). In case ' available, then keep that. Pls refet below details. Input ====================== l_s := ' INSERT INTO TEST' l_P PD := ' UPDATE INTO TEST' l_D := ' DELETE INTO TEST' This is test Output... (4 Replies)
Discussion started by: saurabhbaisakhi
4 Replies

5. Shell Programming and Scripting

perl script to check if empty files are created and delete them and run a shell script

I have a local linux machine in which the files are dumped by a remote ubuntu server. If the process in remote server has any problem then empty files are created in local machine. Is there any way using perl script to check if the empty files are being created and delete them and then run a shell... (2 Replies)
Discussion started by: hussa1n
2 Replies

6. UNIX for Dummies Questions & Answers

How to delete partial duplicate lines unix

hi :) I need to delete partial duplicate lines I have this in a file sihp8027,/opt/cf20,1980182 sihp8027,/opt/oracle/10gRelIIcd,155200016 sihp8027,/opt/oracle/10gRelIIcd,155200176 sihp8027,/var/opt/ERP,10376312 and need to leave it like this: sihp8027,/opt/cf20,1980182... (2 Replies)
Discussion started by: C|KiLLeR|S
2 Replies

7. Shell Programming and Scripting

AWK - Print partial line/partial field

Hello, this is probably a simple request but I've been toying with it for a while. I have a large list of devices and commands that were run with a script, now I have lines such as: a-router-hostname-C#show ver I want to print everything up to (and excluding) the # and everything after it... (3 Replies)
Discussion started by: ippy98
3 Replies

8. Shell Programming and Scripting

Shell script to delete specify directory

I have the following directories under "0.0.0.0" /scratch/builds/snapshotBuilds/0.0.0.0 drwxr-xr-x+ tested-571 drwxr-xr-x+ tested-576 drwxr-xr-x+ tested-597 drwxr-xr-x+ 600 drwxr-xr-x+ 601 drwxr-xr-x+ 602 drwxr-xr-x+ 603 drwxr-xr-x+ tested-604 drwxr-xr-x+ tested-605... (13 Replies)
Discussion started by: ibad_urs
13 Replies

9. Shell Programming and Scripting

Delete db records from shell script

Hello Mates, I would request your help in a shell script, simply I need to delete some matching db table records (rows) to ones in a given file: ------------------------------ #!/bin/bash SQL="delete from numberlist where msidn='';" MYSQL_USER="<your-user>"... (4 Replies)
Discussion started by: EAGL€
4 Replies

10. Shell Programming and Scripting

Script to compare partial filenames in two folders and delete duplicates

Background: I use a TV tuner card to capture OTA video files (.mpeg) and then my Plex Media Server automatically optimizes the files (transcodes for better playback) and places them in a new directory. I have another Plex Library pointing to the new location for the optimized .mp4 files. This... (2 Replies)
Discussion started by: shaky
2 Replies
DBA_OPEN(3)								 1							       DBA_OPEN(3)

dba_open - Open database

SYNOPSIS
resource dba_open (string $path, string $mode, [string $handler], [mixed $...]) DESCRIPTION
dba_open(3) establishes a database instance for $path with $mode using $handler. PARAMETERS
o $path - Commonly a regular path in your filesystem. o $mode - It is r for read access, w for read/write access to an already existing database, c for read/write access and database creation if it doesn't currently exist, and n for create, truncate and read/write access. The database is created in BTree mode, other modes (like Hash or Queue) are not supported. Additionally you can set the database lock method with the next char. Use l to lock the database with a .lck file or d to lock the databasefile itself. It is important that all of your applications do this consis- tently. If you want to test the access and do not want to wait for the lock you can add t as third character. When you are abso- lutely sure that you do not require database locking you can do so by using - instead of l or d. When none of d, l or - is used, dba will lock on the database file as it would with d. Note There can only be one writer for one database file. When you use dba on a web server and more than one request requires write operations they can only be done one after another. Also read during write is not allowed. The dba extension uses locks to prevent this. See the following table: DBA locking +-------------+---------------+---+---+---+---+---+---+---+ |already open | | | | | | | | | | | | | | | | | | | | | $mode = "rl" | | | | | | | | | | | | | | | | | | | | $mode = "rlt" | | | | | | | | | | | | | | | | | | | | $mode = "wl" | | | | | | | | | | | | | | | | | | | | $mode = "wlt" | | | | | | | | | | | | | | | | | | | | $mode = "rd" | | | | | | | | | | | | | | | | | | | | $mode = "rdt" | | | | | | | | | | | | | | | | | | | | $mode = "wd" | | | | | | | | | | | | | | | | | | | | $mode = "wdt" | | | | | | | | | | | | | | | | | | +-------------+---------------+---+---+---+---+---+---+---+ | not open | | | | | | | | | | | | | | | | | | | | | ok | | | | | | | | | | | | | | | | | | | | ok | | | | | | | | | | | | | | | | | | | | ok | | | | | | | | | | | | | | | | | | | | ok | | | | | | | | | | | | | | | | | | | | ok | | | | | | | | | | | | | | | | | | | | ok | | | | | | | | | | | | | | | | | | | | ok | | | | | | | | | | | | | | | | | | | | ok | | | | | | | | | | | | | | | | | | |$mode = "rl" | | | | | | | | | | | | | | | | | | | | | ok | | | | | | | | | | | | | | | | | | | | ok | | | | | | | | | | | | | | | | | | | | wait | | | | | | | | | | | | | | | | | | | | false | | | | | | | | | | | | | | | | | | | | illegal | | | | | | | | | | | | | | | | | | | | illegal | | | | | | | | | | | | | | | | | | | | illegal | | | | | | | | | | | | | | | | | | | | illegal | | | | | | | | | | | | | | | | | | |$mode = "wl" | | | | | | | | | | | | | | | | | | | | | wait | | | | | | | | | | | | | | | | | | | | false | | | | | | | | | | | | | | | | | | | | wait | | | | | | | | | | | | | | | | | | | | false | | | | | | | | | | | | | | | | | | | | illegal | | | | | | | | | | | | | | | | | | | | illegal | | | | | | | | | | | | | | | | | | | | illegal | | | | | | | | | | | | | | | | | | | | illegal | | | | | | | | | | | | | | | | | | |$mode = "rd" | | | | | | | | | | | | | | | | | | | | | illegal | | | | | | | | | | | | | | | | | | | | illegal | | | | | | | | | | | | | | | | | | | | illegal | | | | | | | | | | | | | | | | | | | | illegal | | | | | | | | | | | | | | | | | | | | ok | | | | | | | | | | | | | | | | | | | | ok | | | | | | | | | | | | | | | | | | | | wait | | | | | | | | | | | | | | | | | | | | false | | | | | | | | | | | | | | | | | | |$mode = "wd" | | | | | | | | | | | | | | | | | | | | | illegal | | | | | | | | | | | | | | | | | | | | illegal | | | | | | | | | | | | | | | | | | | | illegal | | | | | | | | | | | | | | | | | | | | illegal | | | | | | | | | | | | | | | | | | | | wait | | | | | | | | | | | | | | | | | | | | false | | | | | | | | | | | | | | | | | | | | wait | | | | | | | | | | | | | | | | | | | | false | | | | | | | | | | | | | | | | | | +-------------+---------------+---+---+---+---+---+---+---+ ook: the second call will be successfull. owait: the second call waits until dba_close(3) is called for the first. ofalse: the second call returns false. oillegal: you must not mix "l" and "d" modifiers for $mode parameter. o $handler - The name of the handler which shall be used for accessing $path. It is passed all optional parameters given to dba_open(3) and can act on behalf of them. RETURN VALUES
Returns a positive handle on success or FALSE on failure. CHANGELOG
+--------+---------------------------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------------------------+ | 4.3.0 | | | | | | | It's possible to open database files over net- | | | work connection. However in cases a socket con- | | | nection will be used (as with http or ftp) the | | | connection will be locked instead of the resource | | | itself. This is important to know since in such | | | cases locking is simply ignored on the resource | | | and other solutions have to be found. | | | | +--------+---------------------------------------------------+ SEE ALSO
dba_popen(3), dba_close(3). PHP Documentation Group DBA_OPEN(3)
All times are GMT -4. The time now is 03:00 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy