It is hard enough to do what is right. Our wants, desirers, egos, social pressure, and the like often get in the way of acting properly. Even when we do the right thing, our motivation may not be the purest. We may act the way we do as a method of receiving the accolades of others; for honour, wealth, or acceptance in a social group.
Our Sages understood this difficulty, teaching that "a person should involve themselves in Torah and mitzvoth shelo lishma, not for the name of G-d, for from doing it shelo lishma one will [eventually] come to do it lishma, for the name of G-d". This teaching, mentioned in a number of places in the Talmud (see, for example, Pesachim 50b), is introduced with the word leolam, literally translated as always or forever. Rav Chaim of Volozhin (Nefesh HaChaim, Chapter 3) explains that it is not possible for one to be 100% motivated for the sake of heaven. Leolam, being human beings, there will always be an element of shelo lishma in our mitzvah observance. Hopefully, as we mature and a particular mitzvah becomes second nature, our level of lishma increases.
Our Sages express great praise for those able to reach high levels of lishma. "Rabbi Meir says: Whoever engages in Torah lishma merits many things; moreover, the whole world is worthwhile for his sake alone. He is called friend, a lover of G-d, a lover of mankind; he makes G-d happy, he makes people happy" (Avot 6:1), and on and on as our Sages wax poetic about those who act lishma.
While lishma is great, shelo lishma is fine, too. Thus, it comes as a little bit of a surprise to come across "what Rav Benah used to say....whoever is involved in Torah shelo lishma, it becomes for him a death potion" (Ta'anit 7a). We have a similar sentiment expressed that, "whoever is engaged in Torah shelo lishma, it would have been better had he not been born" (Brachot 17a). The standard resolution to this contradiction—expressed on our page by Tosafot, c.v. v'chol haosek—is that there are two types of shelo lishma. If one hopes for some personal benefit, "to be called a rebbe or to get honour" (it's most interesting how being a rebbe is not to be equated with getting honour), then such is fine, even if not ideal. But if one learns Torah lekanter, to ridicule Torah, then such learning is a death potion. Often one learns not to know how to act, or not even for personal glory, but to hurt others. The student who learns something just so he can potentially embarrass his teacher is using the power of Torah in a most destructive way.
The Netziv (Meisheev Davar 1:46) offers an alternate resolution, one that is very scary indeed. He distinguishes between doing what one is obligated to do, and what one is innovating on his own. When one observes Jewish law as required, then motivation is much less significant. After all, for one who accepts halacha as binding, one is acting as he or she must, and cannot be faulted for a lack of pure motivation. By definition, his or her action demonstrates acceptance of the Divine will. However, if one wants to do something for which there is no obligation, one better ensure that one is motivated for the sake of heaven. The specific case the Netziv was dealing with involved starting a "break-away" shul (some things never change) due to some perceived (or maybe even real) religious infraction in the shul. The Netziv warns the people to be very, very careful, and opens his response with the expression that he read the question, and as a result, he feels "vinegar from my teeth and smoke from my eyes".
When Rav Herschel Schachter discussed this responsum, he often used as an example those who take on leadership positions in the Jewish community; possibly the highest level of serving G-d-if done for the right reason. It is for this reason we daven every week that "all who are involved in community work b'emunah, faithfully", should be blessed. The importance of pure motivation in public work is doubly important as, by definition, those who work in the public sphere must take decisions that are detrimental to some, maybe even many. If done because one truly believes that this is necessary for the greater public good—well, that is what it means to be a leader. But if one harms others for some political or financial gain, our tradition has very harsh things to say about such a person.
Perhaps there is a third approach. When the Gemara refers to acting shelo lishma as something positive, it uses the expression "Torah u'mitzvoth". But when referring to the negative aspect of acting shelo lishma, it leaves out the term mitzvoth, mentioning only Torah. When performing mitzvoth, motivation takes a back seat to action. But when we are talking about learning Torah, learning must lead to action. If one learns Torah without any intention to actually implement what he or she learned in daily life, one runs the risks of destroying Torah. Instead of a Torah Chaim, a living guide to life, it becomes a book of intellectual curiosity—a nice museum piece with little practical import.
As the Mishnah in Pirkei Avot continues, acting lishma prepares one to be "righteous, pious, upright, trustworthy, far from sin....". It would do us all well to try and not only do what is right, but do so for the right reason.
 Lishma is usually translated as "for its own sake". Lishma, literally means "for its name"—and thus, I prefer to translate lishma as "for the name of G-d". We sanctify G-d's name by doing mitzvoth.