LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-18-2011, 04:37 AM   #1
danishgambit
LQ Newbie
 
Registered: Sep 2009
Location: glasgow, scotland
Posts: 25

Rep: Reputation: 0
strange behaving using find with cmin in script


Morning,

hoping you might be able to help with some strange (to me) behaviour I'm seeing in one of the scripts I use.

we have a process that archives off 3 files every 30 mins. My script runs every 30 mins checking for files created in the last 30 mins and scp's them elsewhere.

The script generally runs fine, transferring the expected files across, but every evening when it runs at about 11.30, it sends every file in the sub-directories across, and looking at the date/time stamps against the files I've no idea why.

the script excerpt is

CheckInterval=30
for FileToSend in `find . -type f -cmin -$CheckInterval`
do
if scp -rp $FileToSend......
.....
done


TIA

DanishGambit.
 
Old 11-18-2011, 07:16 AM   #2
Nominal Animal
Senior Member
 
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
Blog Entries: 3

Rep: Reputation: 946Reputation: 946Reputation: 946Reputation: 946Reputation: 946Reputation: 946Reputation: 946Reputation: 946
-cmin does not look at file creation time, it looks at the last status change. If you use e.g. SELinux, you might have a security context setting script that runs then. That would be a status change.

Try last modification time, -mmin instead.

Also, you do realize your script will break if you have a file with whitespace in the name? If you use Bash, then you might consider
Code:
find . -type f -mmin -$CheckInterval -print0 | while read -rd "" FileToSend ; do
    if scp -p "$FileToSend" ...
done
which will work correctly for all file names in Linux. Note that the body of the while loop is run in a subshell, so no changes to variables are seen outside the loop. If you need to pass variables outside the loop body, use form
Code:
while read -rd "" FileToSend ; do
    if scp -p "$FileToSend" ...
done < <(find . -type f -mmin -$CheckInterval -print0)
instead.
 
Old 11-18-2011, 08:29 AM   #3
danishgambit
LQ Newbie
 
Registered: Sep 2009
Location: glasgow, scotland
Posts: 25

Original Poster
Rep: Reputation: 0
Hi Nominal Animal,

thanks for the response, I'll change the script to use mmin tonight and see how it goes. Whitespace isn't an issue in this particular instance due to the naming convention used by the file-generating process, but it's something I'll look at incorporating for other scripts, so good tip.

Cheers,

DanishGambit.
 
Old 11-21-2011, 04:07 AM   #4
danishgambit
LQ Newbie
 
Registered: Sep 2009
Location: glasgow, scotland
Posts: 25

Original Poster
Rep: Reputation: 0
solved

Morning,

just to confirm that I've tried my script using mmin rather than cmin and that's sorted the issue.

Thanks,

DG.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Init script behaving differently when run on machines in the UK vs US BrianK Programming 6 07-21-2011 01:04 AM
[SOLVED] 'Find' command not behaving in a script devmoc Linux - Software 2 02-25-2011 03:36 AM
PIPE find results to tar not behaving as expected. a1danel Linux - Newbie 4 01-15-2011 02:50 PM
aptitude behaving strange: purge is not done, dir not there?? browny_amiga Linux - General 1 12-31-2010 01:40 AM
scp from a linux behaving strange and fubar'ing permissions on destination bsd system rg.viza Linux - Security 3 07-07-2007 04:00 PM


All times are GMT -5. The time now is 06:52 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration