Find 30 Days Old And Delete Prints Error Msg File Not Found After Deleting It

I have a shell script to find folders which are 25 days older and delete it, and put the deleted folder details into log file like this

Code:
 find /ahome/xxx/$FOLDER -type d -mtime +25  -exec ls -ld {} \;  -exec rm -rf {} \;  >> mylogfile.log

after running this command it deletes the folder and logs the folder deleted. But also print error msg
Code:
find: /ahome/prksh/dir/test: No such file or directory

How to suppress the error msg


Similar Content



Is It Food Have Find Command Running In Cron Every Day Once To Delete Older Files

I need to clean-up some folder. I have a cron job which uses find command to find and delete 25 days older file.

Code:
find $FOLDER_PATH/$FOLDER -depth -regex  ^$FOLDER_PATH/$FOLDER/[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ -type d -mtime +25  -exec ls -ld {} \;   >> /tmp/deleted_folders.log

When this running it occupies 1-3% of cpu. And it may take longer time based on the folder size.

Is it ok to have find command running as cron job ?

Command Manual Working But Not On Cron

Hi

When i run this command manually on Centos 6.6 it works:

Code:
/usr/bin/find /backup/ -type d -mtime +1 -print0 | xargs -0 rm -rf

but as a cron job it doesn't as i can see a folder with files there from Mar 28:

Code:
55 5 * * * /usr/bin/find /backup/ -type d -mtime +1 -print0 | xargs -0 rm -rf

And here are the logs from cron that it is executing this at the correct time :

Code:
Mar 30 05:55:01 server CROND[9526]: (root) CMD (/usr/bin/find /backup/ -type d -mtime +1 -print0 | xargs -0 rm -rf)

Any ideas why?

Thanks

How To Run Shell Script In Any Folder Except The Folder Which Contains The Shell Script

I am using a shell script named by test.sh, for example containing
Code:
address="$PWD"
echo "$address"

.
If I put it in folder temp1, and run test.sh, then it will give me the address of the current directory. But if I am now in folder temp2, and I want to run test.sh, I always need to copy test.sh to folder temp2, and then run it. Is there a way that I can run test.sh without copying it? I am not root user.

Syntax Help To Delete Some Files From A Directory On Centos

Hi

I have a folder :

Code:
/usr/local/src/myfolder

and i have there a few folders and files ...

Now i want to delete from this folder the files named:

Code:
file1.txt 
image.jpg
info.html
another.txt

and leave all the rest folders and files...

How is the correct syntax for this?

If it is possible to not use cd /usr/local/src/myfolder and then rm -r .... so i can run it from everywhere ....

Thanks

How To Delete Number Of Files

I'm trying to figure out if find could do this. I have a folder with 1000 files. I want to delete 150 files on that folder regardless of timestamp and filename. Is there a tool, command or option on find that could do this, please let me know.

Combining mtime or ctime to find is not advisable since it will not count the files or even if there are matches, I would still need to sum up the files until I reach 150 files.

Any suggestions?

Grub Directory Has Disappeared - Can't Reinstall Grub

I have tried installing a Ubuntu OS onto a partition (sda3).
When I had difficulties with the install, I decided to delete everything from the partition.

But now when I boot the computer, I get taken to the 'grub rescue' prompt.
I have tried to find grub in my other partitions (sda1 and sda2).
However, the command 'ls (hd0,msdos1)/' for example, does not show a grub directory.
It must've transferred grub to sda3 somehow and now I've deleted it.

I have debian live USB and am trying to install grub with:
Code:
apt-get install-grub /dev/sda

But I get the error message:
Code:
bash: grub-install: command not found

So now I don't know what's going on. Can anyone please help?

Simple Script Question: ${LOGFILES}.* Not Working

This should be a nice and simple one !

I have a script:

Code:
LOGFILES="schedule_download.log schedule_download_AccountancyServices.log schedule_download_FinancialControl.log schedule_download_IncomeCollection.log schedule_download_banner.log manual_download.log manual_download_AccountancyServices.log manual_download_bacs_cheques.log manual_download_FinancialControl.log manual_download_IncomeCollection.log manual_download_banner.log manual_download_Procurement.log manual_upload.log"

LOGDATE=`date +%Y%m%d`

for file in $LOGFILES
do
    cp $file $file.$LOGDATE
done

## Remove log files older than 30 days

for file1 in ${LOGFILES}.*
do
  find $file1 -mtime +30 -exec rm -v \;
done

However, the 2nd part isn't recognizing the files with a date suffix, ie. manual_download_banner.log.20150114 and is instead picking up all the $LOGFILES.

I've tried many variations $LOGIFILES.* and its driving me mad !

Thanks in advance.

Cp -r *.* /<dest Folder>: What Does *.* Literally Mean In Linux?

I have been using this command a lot lately:
Code:
sudo cp -r *.*  /<dest folder owned by root>

Goal: to copy all contents of current folder into destination folder.

I know there are other ways, and have tried several, but gave up in confusion (was also in a hurry to get on with it). Finally gave the windows *.* a shot, and it did exactly what I wanted.

Now that my task is completed, it would be nice to know what *.* literally means in Linux. I just looked though man cp, and also ran Code:
info coreutils 'cp invocation'

but didn't see any '*' options listed. Now I remember having come across '.' before somewhere, in the cp command, so possibly the '*' are ignored, and the only thing that matters is the 'dot'?

How To Determine If Syntax Array=( Str1 Str2 Str3 ) To Declare Array Is Valid

Hi, I am creating a Korn shell script and need to create an array where each element corresponds to one line of an input file. Being able to do the following would be awesome: Code:
array=( $(cat file.txt) )

However, I'm finding that not all of my development boxes allow this. Some return this: Code:
ksh: syntax error: `(' unexpected

I suspect this has something to do with the Korn shell version. Does anyone know how I can find out what version is required in order to be able to declare arrays, as above? Or is this an OS version issue?

I would really appreciate any tips on how I can find out the minimum requirements for this syntax to be valid.

Thanks.

Shell Script Problem

Hi,

I'm wondering if anyone can help me make a script that searches through a specific folder (in this case /tmp ) for files with a given permissions (755) and then delete all the other files with different permissions?

The correct permission should be, as mentioned 755, and those are the files that should be kept (not deleted).
All other files in this folder with different permissions should be deleted.

Thanks!