Creating a lock file in csh?

Daniel Smith - Fun Now, Worry Later daniel at island.COM
Fri Apr 19 12:54:24 AEST 1991


> In article <1991Apr15.205654.26253 at unhd.unh.edu> al at unhd.unh.edu (Anthony Lapadula) writes:
> >I'll soon be writing a script (most likely in csh) that has at least
> >one critical section ...
> >
> >I had thought that creating a lock file -- and checking for its presence
> >when starting up -- would be a reasonable way to solve the problem.
> >
> >-- Anthony (uunet!unhd!al, al at cs.unh.edu) Lapadula


[someone posted a good solution]

	And another use of a "lock file" is to flag when to stop doing
something.  This section is used to check how a tape extraction is going,
which happens in the background...the foreground gets the task of reporting
how much has been accomplished.  It would be easy to check the existence of
the lock file and avoind this whole section in the first place.

[$CR is set to: `echo X | tr 'X' '\015'`]

	touch eps_extract_lock
	(tar xvf $tape_dev > tapelist) >& tape_errs ; rm eps_extract_lock &

	cat << +++
`clear`
		Extracting tape...

+++

	while ( -e eps_extract_lock )
		@ so_far=`du -s | awk ' { print $1 }'`
		set percent_done=`bc` << +++
scale=1
($so_far * 100) / $disk_space_needed
+++
		echo -n '		'percent done: $percent_done + |\
							 tr '+' "$CR"
		sleep 1
		if ( ! -z tape_errs) then
			cat << +++
`clear`

	It looks like there is a problem with the tape:

`cat tape_errs`

	Perhaps one of these things occurred:

		tape got pulled out of the drive?

		cable loose or fell out?

		power turned off to tape drive?

		full moon?

	You may wish to try again with a different tape.  Exiting this script.

+++
		goto bail_out
		endif
	end

-- 
daniel at island.com       Daniel Smith, Island Graphics, (415) 491 0765 x 250(w)
daniel at world.std.com      4000 CivicCenterDrive SanRafael MarinCounty CA 94903
dansmith at well.sf.ca.us      Fax: 491 0402 Disclaimer: Hey, I wrote it, not IG!
falling/yes I'm falling/and she keeps calling/me back again - IJSaF, Beatles



More information about the Comp.unix.shell mailing list