Well firstly, the repetition of code hardly seems necessary. I wuold guess there are better system admin ways to do this, but based on the current information, I would go with something like:
Code:
OS=$(uname -s)
case "$OS" in
SunOS) locked=LK;;
Linux) locked=locked;;
esac
while IFS=":" read -r name _
do
passwd -S "$name" | grep "$locked" > /tmp/$(hostname).LOCKED
chage -l "$name" | grep -E '(Password|Account) expires' > /tmp/$(hostname).EXPIRED
done</etc/passwd
It may need some tweaking and not sure what shell you will be using, but you should get the idea.