LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 12-09-2008, 10:50 AM   #1
jimbo1954
Member
 
Registered: Oct 2006
Location: High Wycombe, Bucks, UK.
Distribution: Debian and Fedora Core in equal measure
Posts: 264

Rep: Reputation: 33
Locking files with a script


Apologies if this is a trivial question, but I'm just starting out with scripts and not too sure what I'm doing

I have a sequence of scripts, the first, called "checker.sh" is very small and light-weight and runs under cron, and simply either finds a file in a predefined location and kicks off another script, or if no file is present, exits and waits for cron to come round again.

The second script, "mover.sh" moves the file from the original location to a transit directory, calls an Expect script to sftp it to another system, then on completion of the sftp, moves the file to a third directory to show it has actually been sftp-ed.

I would like to check the lock status of the file in the first directory, so the second script doesn't try to move a half-copied file. I also want to check the lock status of the file as it enters the transit directory, so I can be sure it has moved across completely before I try to kick of sftp. There are other areas where I may need to not only check the status, but also lock and unlock files to ensure completeness and integrity.

Are there any good tutorials out there, or do any of you have useful and documented script snippets that I could use...

Thanks!
 
Old 12-09-2008, 10:58 AM   #2
SlowCoder
Senior Member
 
Registered: Oct 2004
Location: Southeast, U.S.A.
Distribution: Debian based
Posts: 1,250

Rep: Reputation: 164Reputation: 164
lsof (list open files) will list all currently open files, along with their opening process.
 
Old 12-09-2008, 11:57 AM   #3
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,039

Rep: Reputation: 98
Alternativly:
find ${Directory} -type f -mmin +5

would find all file in ${Directory} and below (could use maxdepth to limit this) that were last modified more than 5 minutes ago.
 
Old 12-09-2008, 12:02 PM   #4
David1357
Senior Member
 
Registered: Aug 2007
Location: South Carolina, U.S.A.
Distribution: Ubuntu, Fedora Core, Red Hat, SUSE, Gentoo, DSL, coLinux, uClinux
Posts: 1,302
Blog Entries: 1

Rep: Reputation: 107Reputation: 107
Quote:
Originally Posted by jimbo1954 View Post
I would like to check the lock status of the file in the first directory, so the second script doesn't try to move a half-copied file.
If you "sftp" the file with a temporary name and then use "mv" to rename it with the final name, that should get around the need to use any locking mechanism.
 
Old 12-10-2008, 05:37 AM   #5
jimbo1954
Member
 
Registered: Oct 2006
Location: High Wycombe, Bucks, UK.
Distribution: Debian and Fedora Core in equal measure
Posts: 264

Original Poster
Rep: Reputation: 33
Thanks Guys!

Some useful contributions there! Many thanks for all your time and help. I'll be back shortly with more dumb questions
 
  


Reply



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
Problem in Samba on Linux about locking the files neel.gurjar Linux - Server 1 04-16-2008 02:47 AM
To rename files in a directory should I use Bash script or a Perl Script ? jamtech Programming 7 01-22-2008 11:25 PM
File locking shared files and CIFS dgermann Linux - Networking 0 07-17-2006 09:41 PM
Locking keyboard and mouse from a bash script statman Linux - Security 8 06-29-2005 02:03 AM
vsftp - locking files? amanu1 Linux - Software 1 11-15-2003 07:46 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:33 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
Open Source Consulting | Domain Registration