daily pastebin goal
76%
SHARE
TWEET

nohup.bash wrapper with unique, timestamped log

ExaGridDba Jun 3rd, 2017 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. function usage
  4. {
  5.         echo "usage nohup.bash command ..."
  6.         exit 1
  7. }
  8.  
  9. if (( $# == 0 )) ; then
  10.         usage
  11. fi
  12.  
  13. if [ ! -w . ] ; then
  14.         echo "nohup.bash: the current working directory is not writable by you"
  15.         exit 1
  16. fi
  17.  
  18. logfile=` date +nohup.%Y%m%d.%H%M%S.$$.log `
  19.  
  20. nohup /usr/bin/time $* > $logfile &
  21. bgpid=$!
  22. echo background process id is $bgpid
  23.  
  24. sleep 1
  25.  
  26. chmod go+r $logfile
  27. echo created file:
  28. echo $logfile
  29.  
  30. if kill -0 $bgpid 2> /dev/null ; then
  31.         echo background process $bgpid is running
  32. else
  33.         echo background process $bgpid is not running
  34. fi
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top