Advertisement
ExaGridDba

nohup.bash wrapper with unique, timestamped log

Jun 3rd, 2017
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement