Tagged: Scripting RSS

  • oremj 2:53 pm on July 16, 2009 Permalink | Reply
    Tags: , Python, Scripting   

    Command line pastebin 

    I have been frustrated with copying/pasting command line output to pastebin lately.  To solve the problem I’ve whipped up a simple script to pastebin stdin. Check it out.

     
  • oremj 7:33 pm on December 2, 2008 Permalink | Reply
    Tags: , IT, Scripting   

    Simple bash locking 

    I often need to create lock files in my scripts, so crontab doesn’t spawn more than one process.  This is a simple bash lock file function I like to use:

    function create_lock {
            LOCK_NAME=$1
            if [[ -e "$LOCK_NAME" ]]
            then
                    OLDPID=`cat $LOCK_NAME`
                    if ps p $OLDPID > /dev/null
                    then
                            return 1
                    fi
                    rm $LOCK_NAME
            fi
            echo $$ > $LOCK_NAME
            return 0
    }

    create_lock doesn’t handle race conditions, but it is typically good enough for me.

     
    • cp 9:57 am on January 14, 2010 Permalink | Reply

      You can avoid the race condition by using “set -o noclobber”. Like this:
      if ! (set -o noclobber; echo “$$” > “/tmp/lock”) 2> /dev/null; then
      echo “locking failed”
      exit 1
      fi

c
compose new post
j
next post/next comment
k
previous post/previous comment
r
reply
e
edit
o
show/hide comments
t
go to top
l
go to login
h
show/hide help
esc
cancel