#!/bin/ksh # # Author: Mohit Dubey # Visit http://www.geocities.com/md_seraphin for more goodies! # # This program is distributed under the GNU Public License Version 2 # with the additional privisio that the original author's name and # contact details must be retained as-is in any modified or copied # versions of this program. # if [[ ${#} -lt 1 ]] then printf "\n\tUsage:\n" printf "\t run [/] [ [] []... ]\n" printf "\n\twhere can be any executable script or binary.\n" printf "\tShell environment provided is ksh with background job\n" printf "\tmonitoring activated. The shell will inherit all exported\n" printf "\tsettings of the caller's environment.\n\n" exit fi PROGNAME=${1} RUNCMD="$*" testPattern=$(print ${PROGNAME} | sed '/\//p'| wc -l) if [[ ${testPattern} -eq 2 ]] then RUNPATH=${PROGNAME%/*} PROGNAME=${PROGNAME##*/} else RUNPATH="." fi if [[ ! -x ${RUNPATH}/${PROGNAME} ]] then printf "\n[%s] not found or not an executable!\n\n" ${RUNPATH}/${PROGNAME} exit fi if [[ ! -w ${RUNPATH} ]] then printf "\n[%s] is not writable!\n\n" ${RUNPATH} exit fi printf "\nStarting run...\n" nohup ${RUNCMD} & childPID=$(jobs -l %%| nawk '{printf "%s",$3;}') printf "Spawned process with PID[%s]\n" ${childPID} printf "To terminate the process, use\n" printf "\tkill [-9] %s\n\n" ${childPID}