SHARE
TWEET

CGI Script to start and stop Samba

a guest Mar 13th, 2013 40 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  #!/bin/sh
  2.  
  3. startSamba() {
  4.         /sbin/smbd -D > /dev/null 2>&1
  5.         /sbin/nmbd -D > /dev/null 2>&1
  6. }
  7.  
  8. stopSamba() {
  9.         /sbin/killall smbd
  10.         /sbin/killall nmbd
  11.         while /sbin/ps aux | /sbin/grep -v grep | /sbin/grep -q 'smbd' ; do
  12.                 /sbin/sleep 1
  13.         done
  14. }
  15.  
  16. echo "Content-type: text/html"
  17. echo ""
  18.  
  19. case $QUERY_STRING in
  20. *samba=start*)
  21.         startSamba
  22. ;;
  23. *samba=stop*)
  24.         stopSamba
  25. ;;
  26. *samba=restart*)
  27.         stopSamba
  28.         startSamba
  29. ;;
  30. esac
  31.  
  32. echo "<p>Samba is </p><p>"
  33. if /sbin/ps aux | /sbin/grep -v grep | /sbin/grep -q 'smbd'
  34.         then
  35.                 echo 'running'
  36.                 start="disabled"
  37.                 restart=""
  38.                 stop=""
  39.         else
  40.                 echo 'not running'
  41.                 start=""
  42.                 restart="disabled"
  43.                 stop="disabled"
  44. fi
  45. echo "
  46. <form action='samba.cgi' method='get'>
  47. Choose action:
  48. <button name='samba' type='submit' value='start' $start>Start</button>
  49. <button name='samba' type='submit' value='restart' $restart>Restart</button>
  50. <button name='samba' type='submit' value='stop' $stop>Stop</button>
  51. </form>      
  52. "
  53.  
  54. exit 0
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