3.137.161.222 |    

Navigation

Google Advertisement

Check interval if an script can start.

trigger.inc.sh
  1. #!/bin/bash
  2. # *************************************************************
  3. # file trigger.inc.sh
  4. # date: 2006-02-15 09:59
  5. # author: Marko Schulz - <mschulz@jamba.net>
  6. # description: Check interval if an script can start.
  7. # *************************************************************
  8. #
  9. #
  10. # SYNOPSIS
  11. #
  12. #    # load this file in your main script:
  13. #    test -f ./trigger.lib && source ./trigger.lib || exit 1
  14. #
  15. #    First argument is the path to an date file. Second argument
  16. #    is the interval: Hourly(H), Daily(D), Weekly(W), Monthly(M).
  17. #    ! ( trigger '/path/to/datefile.txt' 'D' ) && exit 0
  18. #    date +'%Y-%m-%d %H:%M:%S' > /path/to/datefile.txt
  19. #    
  20. #    # here beginns your program...
  21. #
  22. # *************************************************************
  23.  
  24. function trigger () {
  25.  
  26. file=$1
  27. date=$( date +'%Y-%m-%d %H:%M:%S' )
  28.  
  29. [ ! -f "$file" ] && ( echo "no file defined" ) && exit 1
  30.  
  31. case "$2" in
  32. 	h|H)
  33. 		# Hourly - get hour from date...
  34. 		temp=$( echo $date | cut -d: -f1-2 )
  35. 		if [ "$( cat $file | cut -d: -f1-2 )" != "$temp" ]; then
  36. 			true
  37. 		else
  38. 			false
  39. 		fi
  40. 	;;
  41. 	d|D)
  42. 		# Daily - get day from date...
  43. 		temp=$( echo $date | awk '{ print $1 }' )
  44. 		if [ "$( cat $file | awk '{ print $1 }' )" != "$temp" ]; then
  45. 			true
  46. 		else
  47. 			false
  48. 		fi
  49. 	;;
  50. 	w|W)
  51. 		# Weekly - get week from date...
  52. 		# ???
  53. 	;;
  54. 	m|M)
  55. 		# Monthly - get month from date...
  56. 		temp=$( echo $date | cut -d- -f1-2 )
  57. 		if [ "$( cat $file | cut -d- -f1-2 )" != "$temp" ]; then
  58. 			true
  59. 		else
  60. 			false
  61. 		fi
  62. 	;;
  63. 	*)
  64. 		echo "modus is not a valid argument"
  65. 		exit 1
  66. 	;;
  67. esac
  68.  
  69. }
  70.  
  71. # *************************************************************
  72. # end of this library...
Parsed in 0.002 seconds at 816.52 KB/s

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

User online
There are 3 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)