![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
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' 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 |
|
||||
|
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."
I hope this helps. bakunin |
|
||||
|
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 | ||
|
|
![]() |
| Bookmarks |
| Tags |
| shell script, shell scripting, unix scripting, unix scripting basics |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|