LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-19-2014, 07:45 AM   #1
varma6009
LQ Newbie
 
Registered: Dec 2014
Posts: 2

Rep: Reputation: Disabled
Question Which options can i use in "flock" to stop multiple script executions.


Actually in my script im using as below:
(
flock -x -w 300 200 || ( echo "[ERROR] Could not reserve lock" && exit 1 )

# My code(Script to take backup)

) 200>/tmp/myscript.lock

In my cron i have written like it should execute for every one hour. So, when my script is running and taking some time to execute, after some time it is allowing cron to run script after an hour even the old script did not complete execution.
So, is there any way that after one hour if the script doesn't complete, it should wait until it is completed and then run another script.
 
Old 12-19-2014, 08:58 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,860
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
And what error [message] did you get?

(Note: please use [code] and [/code] tags when quoting code.)
 
Old 12-19-2014, 09:03 AM   #3
varma6009
LQ Newbie
 
Registered: Dec 2014
Posts: 2

Original Poster
Rep: Reputation: Disabled
I didn't get any error but when i logged into server and checked process there are 24 process(script was being executed every hour even though the last script did not complete execution) running
 
Old 12-19-2014, 09:18 AM   #4
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,860
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
It should be { echo "[ERROR] Could not reserve lock"; exit 1; }

another example:
Code:
#!/bin/sh

exec 9>/tmp/locktest.lock	# 9 = max value for dash

flock -w 10 9 || { echo No lock; exit; }

echo 'Before wait'
sleep 60
echo 'After wait'

flock -u 9
 
  


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
bash script: using "select" to show multi-word options? (like "option 1"/"o zidane_tribal Programming 7 12-19-2015 01:03 AM
What are the options "Nosuid" "mode" "size" in /etc/fstab? tuxfiles.org does not help pstein Linux - Newbie 1 11-16-2012 12:58 AM
[SOLVED] Script to insert line into file that contains multiple """ characters tara Programming 2 02-15-2012 06:43 PM
Firefox ; How to enable "Stop Unresponsive Script" theKbStockpiler Linux - General 1 12-25-2011 02:07 PM
bad "cd" forces script to stop executing. Is there a way to continue rather than exit BrianK Programming 2 03-24-2010 08:51 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:07 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