[NTLUG:Discuss] Flock file hanging around

Stuart Johnston saj at thecommune.net
Mon Jan 28 17:29:25 CST 2013


You shouldn't need the brackets around your flock command.  Here's a 
nice simple example towards the end of this page:

http://mywiki.wooledge.org/BashFAQ/045


On 1/28/2013 5:21 PM, Neil Aggarwal wrote:
> Stuart:
>
> Thank you for your help on this.
>
> I am trying to modify the script to notify root if the processes in my
> script are still executing after an hour, so I modified my script to this:
>
> #!/bin/bash
> LOCKFILE=/var/lock/mylock.lck
>
> (
> if [ flock -n -s 200 ]; then
>    # Execute commands
>    ...
>    sleep 5
> else
>    if [ $(( $(date +%s) - $(date +%s -r $LOCKFILE) )) -gt 3600 ]; then
>      sendmail root "Lock file more than 1 hour old";
>    fi
> fi
> ) 200>$LOCKFILE
>
> I am getting this error on the if statement around the flock command:
> [: too many arguments
>
> I am not sure why it is complaining since the flock command is supposed to
> return a value when called with the -n argument.
>
> Any ideas?
> Is there a better way to do this?
>
> Thanks,
>    Neil
>
> --
> Neil Aggarwal, (972)834-1565, http://UnmeteredVPS.net/centos
> Virtual private server with CentOS 6 preinstalled
> Unmetered bandwidth = no overage charges
>
>
> _______________________________________________
> http://www.ntlug.org/mailman/listinfo/discuss
>




More information about the Discuss mailing list