Welcome all. I am setting up a cron job to run a bash script, and I am worried that the next one may start before the end of the previous one. A small Google search shows that a popular way to solve this problem is to use the command flockas follows:
flock
flock -n lockfile myscript.sh if [ $? -eq 1 ]; then echo "Previous script is still running! Can't execute!" fi
This works great. However, what should I do if I want to check the exit code myscript.sh? No matter which exit code it returns will be overwritten flock, so I don't know if it succeeded or not.
myscript.sh
, flock, flock <fd>, <fd> - . , , ( , , -n)., , , :
flock <fd>
<fd>
-n
( if flock -n 200 then myscript.sh echo $? fi ) 200>lockfile
#!/bin/bash if ! pgrep myscript.sh; then flock -n lockfile myscript.sh fi
, , "myscript.sh" , cron . , , pgrep myscript.sh , , flock.
Perhaps something like this will work for you.
#!/bin/bash RETVAL=0 lockfailed() { echo "cannot flock" exit 1 } ( flock -w 2 42 || lockfailed false RETVAL=$? echo "original retval $RETVAL" exit $RETVAL ) 42>|/tmp/flocker RETVAL=$? echo "returned $RETVAL" exit $RETVAL
Source: https://habr.com/ru/post/1726620/More articles:https://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1726615/interested-in-making-a-php-script-that-increments-ip-address-from-defined-starting-address-to-defined-ending-address&usg=ALkJrhjvcSHXK1_SeJdXtL1tVMKaS8QTTwHTML5 Large canvas - html5Using multiple Javascript frameworks in a project? - javascriptБуферизация вывода PHP - phpUsing setSourceType with an image control panel hides the status bar - iphoneGLSL Normal Shader Generation - optimizationHow to ensure that HTTP is loaded from an authentic executable file - httpHow to interpret g ++ warning - c ++Dynamic Testing Tools - phpExplaining Javascript objects inserted in the DOM? - javascriptAll Articles