Sponsored Content
Full Discussion: Cronjob to notify by mail
Top Forums Shell Programming and Scripting Cronjob to notify by mail Post 302467882 by Chubler_XL on Sunday 31st of October 2010 10:14:08 PM
Old 10-31-2010
Example cron config
Code:
# On the 1st of the month at 8am notify Task 2 jobs
0 8 1 * * /usr/local/bin/mynotify 2
 
# On the 1st and 15th of the month at 7:30am Task 1 jobs
30 7 1,15 * * /usr/local/bin/mynotify 1
 
# On Friday at 11:15pm notify Task 3 jobs
15 23 * 5 /usr/local/bin/mynotify 3
 
# On 1st Apr (1st Quarter) at 8am notify Task 4 jobs
0 8 1 4 * /usr/local/bin/mynotify 4

For quarterly checks you are probably best of creating 1 job for each of the 4 dates (see 1st April above).

Now you just need to write your "mynotify" script that accepts a task number and sends the emails out. It can read your config files.

Code:
$ cat tasks_list.txt
1:1,2,3:Check windows servers' health:Peter Bill
2:4,5:Check the mail server's health:James
3:6,7,8:Check linux server's health:Bill

$ cat name.txt
Bill bill@xxx.com
Peter peter@xxx.com
James james@xxx.com

$ cat mynotify 
TASK=$1
TODO=$(grep "^$TASK" tasks_list.txt)
[ -z "$TODO" ] && exit
JOBS=$(echo $TODO | cut -f2 -d:)
TITLE=$(echo $TODO | cut -f3 -d:)
WHO=$(echo $TODO | cut -f4 -d:)
echo $WHO | tr ' ' '\n' | while read USR
do
    EMAIL=$(grep "^$USR " name.txt | cut -f2 -d' ')
    echo mail to $USR \($EMAIL\)  subject $TITLE  jobs $JOBS  
done

$ ./mynotify 1
mail to Peter (peter@xxx.com) subject Check windows servers' health jobs 1,2,3
mail to Bill (bill@xxx.com) subject Check windows servers' health jobs 1,2,3


Last edited by Chubler_XL; 10-31-2010 at 11:32 PM..
This User Gave Thanks to Chubler_XL For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

process pager - by cell phone or just e-mail notify

hi all.. i need any help. i want to create in my crontab a simple script for verify any process and notify for the status in my e-mail or cell phone. anybody help me? (9 Replies)
Discussion started by: squash
9 Replies

2. UNIX for Advanced & Expert Users

mail from Cronjob

Hi, I'm having a HP UX 11i and 11.0 . I've given the cron access to one of the user. Now he is getting mails on errors only and not on success on execution of the command. How can i make sure that the mail is sent in both the cases of success and failure. Also the mail is going to the lotus... (6 Replies)
Discussion started by: i2admin
6 Replies

3. Post Here to Contact Site Administrators and Moderators

Notify of a new thread

Hi, I wish to be notified whenever there is a new thread posted on any of the forums or atleast the forums that I have registered to. Can this be done. How? I am sure there must be a way to do this, and I feel this is how the moderators must be doing. I know I may not be eligible enough to be... (5 Replies)
Discussion started by: linuxpenguin
5 Replies

4. UNIX for Dummies Questions & Answers

Notify Command.

Hi, I am using the NOTIFY command and I am getting the emails.. I tried MAILX and e-mail is being sent. I want to use NOTIFY to see if my jobs are completed or not. Am I missing something.. All your ideas are greatly appreciated.. Thanks Venky (2 Replies)
Discussion started by: venkyA
2 Replies

5. Shell Programming and Scripting

Cronjob - Redirect mail output to file, LINES & COLUMNS

I currently have an expect script that issues the 'mail' command and sends an 'x' when it receives the & prompt from mail to quit. The expect script is able to do stty rows 100 columns 200 < $spawn_out(slave,name) to set up the number of columns and rows. I would like to get rid of the expect... (0 Replies)
Discussion started by: jharvey
0 Replies

6. UNIX for Advanced & Expert Users

Notify Me when job fail using cron

I would like to be notified when an Informix dbexport job fails on a TRU64 system. My idea is to send an email via telnet, but can only get telnet to do it interactively. I can do the following steps on my UNIX box interactively, but cannot send an email with a script. Can someone help? Is there... (3 Replies)
Discussion started by: ejaggers
3 Replies

7. Shell Programming and Scripting

Using mail command to notify the status of script

Can someone please help me with this script, I'm trying to create system backup on AIX, for this I want to first mount the filesystem if it is not mounted, then create the backup and unmount the filesystem but I'm having problem while using the mail command to notify the status of filesystem... (9 Replies)
Discussion started by: mbak
9 Replies

8. Shell Programming and Scripting

notify-send does not notify real time

Hi, I am having a little trouble getting notify-send to work the way I would like it to. I am using ubuntu - karmic koala 2.6.31-19-generic #56-Ubuntu SMP So here's the problem run the following commands one after the other. notify-send -i info -t 100000 -- "Hi" "world" & notify-send -i... (3 Replies)
Discussion started by: linuxpenguin
3 Replies

9. UNIX for Dummies Questions & Answers

how to cancel a cronjob if the cronjob still running

hi everyone I'm newbie in this forum hope I can get some help here :) I have a command in crontab that executed every 1 minute sometime this command need more than 1 minute to finish the problem is, the crontab execute this command although it's not finish processing yet and causing the system... (7 Replies)
Discussion started by: 2j4h
7 Replies

10. Shell Programming and Scripting

A notify-send Question --

Greetings. I've come across a bit of a problem with notify-send syntax; and wondered if anyone out there had found a solution in the woodpile somewhere :) Here's the snippet which is giving me trouble:notify-send 'Text to display' image_data 300, 300, , , , , /etc/image.pngOutput:Invalid... (0 Replies)
Discussion started by: LinQ
0 Replies
SYSTEMD-NOTIFY(1)						  systemd-notify						 SYSTEMD-NOTIFY(1)

NAME
systemd-notify - Notify service manager about start-up completion and other daemon status changes SYNOPSIS
systemd-notify [OPTIONS...] [VARIABLE=VALUE...] DESCRIPTION
systemd-notify may be called by daemon scripts to notify the init system about status changes. It can be used to send arbitrary information, encoded in an environment-block-like list of strings. Most importantly it can be used for start-up completion notification. This is mostly just a wrapper around sd_notify() and makes this functionality available to shell scripts. For details see sd_notify(3). The command line may carry a list of environment variables to send as part of the status update. Note that systemd will refuse reception of status updates from this command unless NotifyAccess=all is set for the service unit this command is called from. OPTIONS
The following options are understood: -h, --help Prints a short help text and exits. --version Prints a short version string and exits. --ready Inform the init system about service start-up completion. This is equivalent to systemd-notify READY=1. For details about the semantics of this option see sd_notify(3). --pid= Inform the init system about the main PID of the daemon. Takes a PID as argument. If the argument is omitted, the PID of the process that invoked systemd-notify is used. This is equivalent to systemd-notify MAINPID=$PID. For details about the semantics of this option see sd_notify(3). --status= Send a free-form status string for the daemon to the init systemd. This option takes the status string as argument. This is equivalent to systemd-notify STATUS=.... For details about the semantics of this option see sd_notify(3). --booted Returns 0 if the system was booted up with systemd, non-zero otherwise. If this option is passed, no message is sent. This option is hence unrelated to the other options. For details about the semantics of this option, see sd_booted(3). --readahead= Controls disk read-ahead operations. The argument must be a string, and either "cancel", "done" or "noreplay". For details about the semantics of this option see sd_readahead(3). EXIT STATUS
On success, 0 is returned, a non-zero failure code otherwise. EXAMPLE
Example 1. Start-up Notification and Status Updates A simple shell daemon that sends start-up notifications after having set up its communication channel. During runtime it sends further status updates to the init system: #!/bin/bash mkfifo /tmp/waldo systemd-notify --ready --status="Waiting for data..." while : ; do read a < /tmp/waldo systemd-notify --status="Processing $a" # Do something with $a ... systemd-notify --status="Waiting for data..." done SEE ALSO
systemd(1), systemctl(1), systemd.unit(5), sd_notify(3), sd_booted(3) systemd 208 SYSTEMD-NOTIFY(1)
All times are GMT -4. The time now is 07:29 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy