My first script
So I’ve been dicking around with my linux ubuntu server. I installed postfix and courier-imap to set up an IMAP server on my network so whenever I feel like switching email clients I don’t lose all my mail. Well, the first thing I apparently have to do is make sure postfix is working right, and that involves configuring my /etc/postfix/main.cf file.
So I start looking into it, and come to a part where I have to list my external IP address as part of the config file so some kind of loop doesn’t happen. Well… how do I automate this? Here’s the script I eventually came up with:
sed ’s/^proxy_interfaces = .*$/proxy_interfaces = ‘`wget -qO- http://checkip.dyndns.org | html2text | cut -c21-35`’/’ /etc/postfix/main.cf > /etc/postfix/main.cf.tmp
mv /etc/postfix/main.cf /etc/postfix/main.cf.old
mv /etc/postfix/main.cf.tmp /etc/postfix/main.cf
/etc/init.d/postfix restart > /dev/null
I know it doesn’t show up right, but the first line starts from sed and ends with “> /etc/postfix/main.cf.tmp”, and what it does is query that web address which returns my IP as seen from the outside, then replaces the string “proxy_interfaces = blah blah blah” with a correct string that states what my IP address is from the outside. Anyway, I stuck this script in my cron.hourly folder so each hour it gets my external IP and updates my postfix main.cf file accordingly, rebooting my postfix daemon silently after each update.
I know my Linux kung-fu is weak, but I consider this a step towards mastery of my OS.
Today: shell scripts. Tomorrow: kernel programming… again! Just call it the “re-education of TJ O”
-TJ
12. September 2007 at 9:58 am :
i have no idea what any of that means, but well done!