marty171

Untitled

Jan 13th, 2017
224
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #! /bin/sh
  2. ### /usr/local/sbin/stoppark: stop Mac10.6.8 Samsung 2T head parks (hdapm fails)
  3.  
  4. ### setup
  5. prog=$0
  6. logfile=/Users/$USER/Library/Logs/StopPark.log
  7. mypid=$$
  8. ps auxwww | grep "$prog" | grep "/bin/sh" | grep -v grep | awk '{print $2}' > $logfile
  9. pids=`cat $logfile`
  10.  
  11. ### at most one copy
  12. running=""
  13. for pid in $pids; do
  14. if [ "$pid" != "$mypid" ]; then running="$running $pid"; fi
  15. done
  16. if [ "$running" != "" ]; then
  17. logger "$prog: ### already running (pid=${running})"
  18. rm -f $logfile
  19. exit 0
  20. fi
  21.  
  22. ### stop head park by write tiny file every 7 sec (attempts park every 8 sec)
  23. logger "$prog: running (pid=$mypid)"
  24. i=0
  25. while [ 1 ]; do
  26. echo $i > $logfile
  27. sleep 7
  28. i=`expr $i + 1`
  29. done
  30.  
  31. ### HOWTO install auto-start for user "myuser"
  32. #vi ~/Library/LaunchAgents/org.myuser.stoppark.plist
  33. #------------------------------------------------------------
  34. #<?xml version="1.0" encoding="UTF-8"?>
  35. #<!DOCTYPE plist PUBLIC -//Apple Computer//DTD PLIST 1.0//EN
  36. #http://www.apple.com/DTDs/PropertyList-1.0.dtd >
  37. #<plist version="1.0">
  38. # <dict>
  39. # <key>Label</key>
  40. # <string>org.myuser.stoppark</string>
  41. # <key>ProgramArguments</key>
  42. # <array>
  43. # <string>/usr/local/sbin/stoppark</string>
  44. # </array>
  45. # <key>KeepAlive</key>
  46. # <true/>
  47. # <key>StandardOutPath</key>
  48. # <string>/Users/myuser/Library/Logs/StopPark.log</string>
  49. # <key>StandardErrorPath</key>
  50. # <string>/Users/myuser/Library/Logs/StopPark.log</string>
  51. # </dict>
  52. #</plist>
  53. #
  54. #------------------------------------------------------------
  55. ### HOWTO interactively start
  56. #launchctl load ~/Library/LaunchAgents/org.myuser.stoppark.plist
RAW Paste Data