Modified shell script to work with dispatch system