Gentoo Archives: gentoo-user

From: Kaushal Shriyan <kaushalshriyan@×××××.com>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] crontab entry
Date: Mon, 24 Mar 2008 10:03:34
Message-Id: 6b16fb4c0803240303k39f430e8n78f1381c84fbde6@mail.gmail.com
In Reply to: Re: [gentoo-user] crontab entry by Dirk Heinrichs
1 On Mon, Mar 24, 2008 at 3:17 PM, Dirk Heinrichs <dirk.heinrichs@××××××.de>
2 wrote:
3
4 > Am Montag, 24. März 2008 schrieb Kaushal Shriyan:
5 > > On Mon, Mar 24, 2008 at 2:44 PM, Dirk Heinrichs <
6 > dirk.heinrichs@××××××.de>
7 > >
8 > > wrote:
9 > > > Am Montag, 24. März 2008 schrieb Kaushal Shriyan:
10 > > > > MAILTO=systems@×××××××.com
11 > > > > 0 18 * * * /home/kaushal/rsync_mysql.sh
12 > > > >
13 > > > > I want my subject line to be "hostxx:yyDB refresh daily"
14 > > > >
15 > > > > is there a way to do it
16 > > >
17 > > > Don't rely on cron to send the mail, use mailx inside your script
18 > > > instead. That means, inside the script, capture all output in a temp.
19 > > > file, then use
20 > > >
21 > > > cat /tmp/file|mailx -s "my subject" systems@×××××××.com
22 > > >
23 > > > HTH...
24 > > >
25 > > > Dirk
26 > >
27 > > Hi Dirk
28 > >
29 > > Below is my script
30 > >
31 > ###########################################################################
32 > >##
33 > >
34 > > #!/bin/bash
35 > > #rsync mysql database shell script
36 > > #author kaushal
37 > > #created on 21/03/2008
38 > >
39 > > TIMESTAMP=`date +%Y-%m-%d-%H:%M:%S:%N`
40 > >
41 > > if rsync -av /var/lib/mysql kaushal@host77:/var/lib/
42 > >
43 > > >/tmp/rsync-${TIMESTAMP}.log 2>&1
44 > >
45 > > then
46 > > echo "Success"
47 > > else
48 > > echo "Please check the file rsync-${TIMESTAMP}.log for errors."
49 > > fi
50 > >
51 > >
52 > ###########################################################################
53 > >##
54 > >
55 > > so according to your suggestion where does this line fits "cat
56 > > /tmp/file|mailx -s "my subject" systems@×××××××.com" <
57 > systems@×××××××.com>
58 > > in my above bash script
59 > >
60 > > Thanks and Regards
61 > >
62 > > Kaushal
63 >
64 > Hmm, if the script is used from cron only, you could reduce it to the
65 > following (note that when run from cron, you may need to use full paths to
66 > your binaries, or set $PATH inside the script):
67 >
68 > /usr/bin/rsync -av /var/lib/mysql kaushal@host77:/var/lib/
69 > 2>&1 |/usr/bin/tee /tmp/rsync-${TIMESTAMP}.log | /usr/bin/mailx -s "My
70 > subject" systems@×××××××.com
71 >
72 > This will mail the output and save it to a file at the same time.
73 >
74 > HTH...
75 >
76 > Dirk
77 >
78
79 Hi Dirk,
80
81 Thanks Dirk
82
83 So the Final script looks like
84
85 ##################################################################################################################
86
87 #!/bin/bash
88 #rsync mysql database shell script
89 #author kaushal
90 #bash script file name rsync_mysql.sh
91 #created on 24/03/2008
92
93 TIMESTAMP=`date +%Y-%m-%d-%H:%M:%S:%N`
94
95 if /usr/bin/rsync -av /var/lib/mysql kaushal@host77:/var/lib/ 2>&1 |
96 /usr/bin/tee /tmp/rsync-${TIMESTAMP}.log | /usr/bin/mailx -s "host77 DB
97 refresh daily" kaushal@×××××××.com
98
99 then
100 echo "Success"
101 else
102 echo "Please check the file rsync-${TIMESTAMP}.log for errors."
103 fi
104
105 ##################################################################################################################
106
107 and the crontab entry would be
108
109 0 18 * * * /home/kaushal/rsync_mysql.sh
110
111
112 Please let me know if its correct
113
114 Thanks again
115
116 Thanks and Regards
117
118 Kaushal

Replies

Subject Author
Re: [gentoo-user] crontab entry Dirk Heinrichs <dirk.heinrichs@××××××.de>