#!/bin/sh(The username and password are public in this building, so I need not worry about the clear-text password.)
wget -O - --post-data 'username=...&password=...' 'http://....' |
html2text | tee /tmp/$$.txt
fgrep -q 'already logged in' /tmp/$$.txt || exit 1
It was strange that /tmp/$$.txt apparently contained the string “already logged in” but the script always exited abnormally (fgrep fails).
I finally found the reason by opening /tmp/$$.txt with bvi (a vi-style hexadecimal editor): the string in the file was actually like this: “You a\bare alr\bread\bdy logged\bd in.” (“\b” stands for backspace character.) That’s why fgrep could not find the string..