diff options
author | Aaron LI <aaronly.me@outlook.com> | 2016-09-09 16:50:39 +0800 |
---|---|---|
committer | Aaron LI <aaronly.me@outlook.com> | 2016-09-09 16:50:39 +0800 |
commit | 50ce0cf0e0933312a5b51eace26d5821379e731d (patch) | |
tree | 876bef64279ee109391c2a433990780dd8aef98d /_bin/get_mail.sh | |
parent | dda8a74155ec276f002f4ddd381a235614e2bf4c (diff) | |
download | dotfiles-50ce0cf0e0933312a5b51eace26d5821379e731d.tar.bz2 |
Add _bin/get_mail.sh for better handle of email fetch
Since ``offlineimap`` sometimes just gets stuck, which blocks new
instance from running, this little script is composed to better
handle this stuck by first force kill existing instance.
However, this script in current state cannot work well with ``mu4e``.
Diffstat (limited to '_bin/get_mail.sh')
-rwxr-xr-x | _bin/get_mail.sh | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/_bin/get_mail.sh b/_bin/get_mail.sh new file mode 100755 index 0000000..a8288cc --- /dev/null +++ b/_bin/get_mail.sh @@ -0,0 +1,30 @@ +#!/bin/sh +# +# Run the command to get emails, and record its PID, which is used +# to kill the program before run it again. +# This is an workaround to solve the stuck issue with `offlineimap`. +# + +# Command to get emails +GET_CMD="offlineimap -o -1" + +# PID file +PID_FILE="${HOME}/.cache/get_mail.pid" + +# Log file +LOG_FILE="${HOME}/.cache/get_mail.log" + + +# Kill the previous process at first. +# For `offlineimap`, it sometimes just stucks ... +if [ -e "${PID_FILE}" ]; then + kill -SIGKILL `cat ${PID_FILE}` + rm ${PID_FILE} +fi + +if [ -e "${LOG_FILE}" ]; then + mv ${LOG_FILE} ${LOG_FILE}.old +fi + +${GET_CMD} > ${LOG_FILE} 2>&1 & +echo $! > ${PID_FILE} |