The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
unix shell script reqd... venkatesht Shell Programming and Scripting 7 11-26-2008 12:56 PM
Kron Shell: deleting all but most recent log files WmShaw Shell Programming and Scripting 2 11-06-2008 12:11 PM
Checklist for Shell Script reqd Shivdatta Shell Programming and Scripting 2 11-30-2007 10:59 AM
shell script: deleting files from a directory onlyc Shell Programming and Scripting 1 07-09-2006 06:41 AM
CRON-Job / Shell-Skript deleting special files ManfredWL Shell Programming and Scripting 9 07-17-2003 03:18 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-18-2008
venkatesht venkatesht is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 68
shell script reqd - deleting files

I have written a script that deletes files:

Requirement: i need to delete the files and to know how many files are deleted i.e the count of files and even i need to display when the started time of deletion and the ending time of deletion. I need to display these two times.

script:

Code:
export j
j=0
for i in `find /opt/CGEYScripts -name "core*" -print`
do echo $i
rm -f $i
j=j+1
done
echo `j'
error:
test1:integ>./Purging.sh
/opt/CGEYScripts/coredumps.ctl
/opt/CGEYScripts/cored
./Purging.sh[8]: j: not found

Can anyone modify the script that meets my requirement, please?

Last edited by bakunin; 12-18-2008 at 07:05 AM.. Reason: added code-tags. Please use them yourself from now on
  #2 (permalink)  
Old 12-18-2008
bakunin bakunin is offline Forum Staff  
Bughunter Extraordinaire
  
 

Join Date: May 2005
Location: In the leftmost byte of /dev/kmem
Posts: 1,628
First, you have used a backquote instead of a dollar sign in the last line where you display the variable j, which is causing the last error.

Second, you should not use backquotes any more, they are outdated. Use "$(...)" instead.

Third, - only if you use ksh - use "print" instead of "echo", because "print" is a built-in while "echo" is an external command.

Fourth, you should not use "for"-loops to cycle through arbitrary lists, because they could become longer than what your shell could fathom. Use a pipeline instead:

Code:
typeset -i DeletedFiles=0
print - "Started purging at: $(date +'<your preferred format here>')"
find opt/CGEYScripts -name "core*" -print | while read filename ; do
     print - "Deleting: $filename"
     rm -f $filename
     (( DeletedFiles += 1 ))
done
print - "Finished purging at: $(date +'<your preferred format here>')"
print - "Deleted $DeletedFiles files."
For a fitting format string for "date" consult the manpage of "date".

I hope this helps.

bakunin
  #3 (permalink)  
Old 12-19-2008
venkatesht venkatesht is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 68
Thanks a lot. It works wonderfully. However, i need to add something to this.

Desired Output:

want to display the output as:

Deleting from the <directory>
<<file1>>
<<file2>>
<<file3>>
;
;
;
<<filen>>

Looking forward...

Thanks in advance,
venkat
Sponsored Links
Closed Thread

Bookmarks

Tags
shell script, shell scripting, unix scripting, unix scripting basics

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:19 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0