18.223.172.252 |    

Navigation

Google Advertisement

Save all crontabs of all unixusers where the UID is greater than 1000.

getcrontab.sh
  1. #!/bin/bash
  2. # *************************************************************
  3. # File: getcrontab.sh
  4. # Date: 2008-07-16 10:55
  5. # Author: Marko Schulz - <info@tuxnet24.de>
  6. # Description: Save all crontabs of all unixusers where the UID is greater than 1000.
  7. # *************************************************************
  8.  
  9. # List of unixuser that will be ignored (space seperated list).
  10. prune="nobody"
  11.  
  12. # Directory where the crontabs will be stored.
  13. directory="/data/backup/$( hostname )/crontabs"
  14.  
  15. # *************************************************************
  16. # This function save the crontab of the current unixuser in
  17. # the backup directory and set the file access to 640. Empty
  18. # crontab files will be deleted.
  19.  
  20. function rc_save_crontab () {
  21.  
  22. local user=$1
  23. local directory=$2
  24.  
  25. # Backup the crontab of the current user.
  26. crontab -u ${user} -l >${directory}/${user} 2>/dev/null
  27.  
  28. # Delete all empty crontabs.
  29. [ ! -s "${directory}/${user}" ] && rm -f ${directory}/${user}
  30.  
  31. # Remove read access for others.
  32. [ -f "${directory}/${user}" ] && chmod o-r ${directory}/${user} 2>/dev/null
  33.  
  34. }
  35.  
  36. # *************************************************************
  37. # Program action...
  38.  
  39. # Replace all spaces into pipe character.
  40. prune=$( echo $prune | sed 's/[[:space:]]\{1,\}/|/g' )
  41.  
  42. # Create backup directory if not exists.
  43. [ ! -d "$directory" ] && mkdir -p $directory 2>/dev/null
  44.  
  45. # First, we clean the directory.
  46. rm -f ${directory}/*
  47.  
  48. # Match all vailed unixuser...
  49. for user in $( awk -F: '$1 !~ /('$prune')/ && $3 >= 1000 { print $1 }' /etc/passwd ); do
  50. 	rc_save_crontab "${user}" "${directory}"
  51. done
  52.  
  53. # At last we save the crontab entry from root.
  54. rc_save_crontab "root" "${directory}"
  55.  
  56. # *************************************************************
  57. # EOF
Parsed in 0.004 seconds at 493.08 KB/s

Search
 
Full text search by name and content of a snippet.

User online
There are 8 users online.

Tags Cloud

Latest snippets
str2seconds
(Bash::Function)
is_integer
(Bash::Function)
file_rotate
(Bash::Function)
confirm
(Bash::Function)
is_workingtime
(Bash::Function)
last day of last month
(Bash::Snippets)
crypt_apr1_md5
(PHP::Function)
crypt_apr1_md5
(Perl::Function)
transparent
(CSS)
rfc2822Toiso8601
(PHP::Function)