Hi,
I have a script which will be run the cron weekly, here's the content of the script
Code:
#!/bin/bash
emerge --sync &&
# prepare the mail subject
echo -e 'subject: emerge updates' > /etc/cron.weekly/updates.world &&
# prepare the mail body
emerge -uvDp world >> /etc/cron.weekly/updates.world &&
# sendmail
sendmail root < /etc/cron.weekly/updates.world
Yes, I am using Gentoo Linux.
What I want to do is the sync the portage tree weekly, and send me an email about what needs to be updated. But I never receive a email...When I check the system log, I found something like this:
May 9 04:10:03 david-gentoo sSMTP[18917]: Set MailHub="my.email.com"
May 9 04:10:03 david-gentoo sSMTP[18917]: via SMTP Port Number="25"
May 9 04:10:37 david-gentoo sSMTP[18917]: 220 Esmtp XX Mail Server
May 9 04:10:37 david-gentoo sSMTP[18917]: EHLO gentoo
May 9 04:10:38 david-gentoo sSMTP[18917]: 250 8BITMIME
May 9 04:10:38 david-gentoo sSMTP[18917]: AUTH LOGIN
May 9 04:10:40 david-gentoo sSMTP[18917]: 334 3TGTGEW
May 9 04:10:40 david-gentoo sSMTP[18917]: GW3TGEWRT43
May 9 04:10:41 david-gentoo sSMTP[18917]: 334 DSG345TGDG
May 9 04:10:41 david-gentoo sSMTP[18917]: DGEWT5RGF==
May 9 04:10:42 david-gentoo sSMTP[18917]: 235 Authentication successful
May 9 04:10:42 david-gentoo sSMTP[18917]: MAIL FROM:<
[email protected]>
May 9 04:10:43 david-gentoo sSMTP[18917]: 250 Ok
May 9 04:10:43 david-gentoo sSMTP[18917]: RCPT TO:<
[email protected]>
May 9 04:10:43 david-gentoo sSMTP[18917]: 250 Ok
May 9 04:10:43 david-gentoo sSMTP[18917]: DATA
May 9 04:10:44 david-gentoo sSMTP[18917]: 354 End data with <CR><LF>.<CR><LF>
May 9 04:10:44 david-gentoo sSMTP[18917]: Received: by gentoo (sSMTP sendmail emulation); Sat, 09 May 2009 04:10:02 +0800
May 9 04:10:44 david-gentoo sSMTP[18917]: From: "root" <
[email protected]>
May 9 04:10:44 david-gentoo sSMTP[18917]: Date: Sat, 09 May 2009 04:10:02 +0800
May 9 04:10:44 david-gentoo sSMTP[18917]: To: root
May 9 04:10:44 david-gentoo sSMTP[18917]: Subject: Cron <
[email protected]> test -x /usr/sbin/run-crons && /usr/sbin/run-crons
May 9 04:10:44 david-gentoo sSMTP[18917]: X-Cron-Env: <SHELL=/bin/bash>
May 9 04:10:44 david-gentoo sSMTP[18917]: X-Cron-Env: <PATH=/sbin:/bin:/usr/sbin:/usr/bin>
May 9 04:10:44 david-gentoo sSMTP[18917]: X-Cron-Env: <MAILTO=root>
May 9 04:10:44 david-gentoo sSMTP[18917]: X-Cron-Env: <HOME=/>
May 9 04:10:44 david-gentoo sSMTP[18917]: X-Cron-Env: <LOGNAME=root>
May 9 04:10:44 david-gentoo sSMTP[18917]: X-Cron-Env: <USER=root>
A long list of the out put of command 'emerge --sync'May 9 04:15:44 david-gentoo sSMTP[18917]: killed: timeout on stdin while reading body -- message saved to dead.letter.
May 9 04:15:44 david-gentoo sSMTP[18917]: Timeout on stdin while reading bodyThe last message is why I feel strange. By using the '&&' operator, I suppose every command can only be executed after the previous one have been successfully run. But it look like the command to retrieve the update information and the command to send the email are running in parallel, and since the input of the email is the out put of the updating command, and it takes a long time the retrieve the update information, the email send command failed to execute in time. By checking my system, the file which I used to save the update information is NOT updated at all, but the system DID retrieved the update information.
If my script is not correct, would some one point it out? And help me fix it.
Thanks,
David