Advertisement
Guest User

Untitled

a guest
Oct 20th, 2014
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. #!/bin/sh -e
  2.  
  3. if test $# -eq 0
  4. then
  5. echo usage: $0 shellname [shellname ...]
  6. exit 1
  7. fi
  8.  
  9. file=/etc/shells
  10. # I want this to be GUARANTEED to be on the same filesystem as $file
  11. tmpfile=${file}.tmp
  12.  
  13. set -o noclobber
  14.  
  15. trap "rm -f $tmpfile" EXIT
  16.  
  17. if ! cat $file > $tmpfile
  18. then
  19. cat 1>&2 <<EOF
  20. Either another instance of $0 is running, or it was previously interrupted.
  21. Please examine ${tmpfile} to see if it should be moved onto ${file}.
  22. EOF
  23. exit 1
  24. fi
  25.  
  26. for i
  27. do
  28. if ! grep -q "^${i}$" $tmpfile
  29. then
  30. echo $i >> $tmpfile
  31. fi
  32. done
  33.  
  34. chmod --reference=$file $tmpfile
  35. chown --reference=$file $tmpfile
  36.  
  37. mv $tmpfile $file
  38.  
  39. trap "" EXIT
  40. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement