#!/bin/bash PASS_FILE="/dev/shm/max_aber_passwd" PID="/dev/shm/max_mbsync_loop_pid" LOG="/dev/shm/max_mail_log" touch $LOG clean_up() { kill -TERM $(cat $PID) rm $PID sync_mailboxes rm $PASS_FILE exit } trap clean_up SIGTERM SIGHUP SIGINT sync_mailboxes() { /usr/bin/mbsync -c /home/max/.mbsync.aber -a >> $LOG 2>&1 } sync_mailboxes_loop() { while true do sync_mailboxes sleep 20 done } rm -f $PASS_FILE touch $PASS_FILE chown max:max $PASS_FILE chmod 600 $PASS_FILE pass Aber/Main | head -n 1 > $PASS_FILE if [[ "${PIPESTATUS[0]}" -ne 0 ]]; then echo "Password not available" exit fi sync_mailboxes_loop& >> $LOG 2>&1 echo $! > $PID /usr/bin/mutt -F ~/.mutt/mutt.uk.ac.aber.maf54 clean_up