samedi 14 juillet 2012

how to ceate .sh script , how to send mails from Cron linux Ubuntu


We set up  msmtp and mutt, and we'll use these tools to be able to send  mail notifications from Cron (sheduled task) trought a simple script :

we launch kate :


sudo-s
kate


We'll paste this command below


#!/bin/sh
mutt -s "k-tux test" totobiscuit@gmail.com < /home/polux/Documents/test.txt


we'll save this script to /home/polux/Documents/muttscrip.sh (muttscrip.sh is the file name) 
In order to make this script possible to be run, here is the command  to tip in the "Documents" folder :





chmod +x muttscrip.sh



The script is ready  !
It could be launched with the command below in the same folder :

 ./muttscrip.sh

We'll open crontab , tip this:

crontab -e 

It's better to choose nano as text editor, we'll create our first sheduled task, 
 do "ctrl+o" and we'll tip it on the bottom "55 9..."





# m h  dom mon dow   command
55 9 * * *  /home/polux/Documents/muttscrip.sh 


m = minute 
h =hour
dom = month day 
mon = month of the year 
dow = day of the week ( 1 to 7 )
 /home/polux/Documents/muttscrip.sh = script path


We'll leave and save crontab with "ctrl+x", and "y",and  "enter"
It is possible to check crontab with this command

contab -l 

A mail should be sentat 9.55 !

The EnD. 

Aucun commentaire: