I recently saw in The Moshiach Times, a popular Chabad-Lubavitch publication for children, an exhortation to "do a mitzvah for moshiach": to do a mitzva with the specific purpose of hastening the arrival of the days of mashiach. Is there a source for this: that one should do mitzvos for, at least in part, this purpose, or with, at least in part, this intent? (I know doing mitzvos can hasten the arrival of the days of mashiach, and I also know we pray for their hastened arrival; those are not my question.)
I think that the question presupposes that the coming of Moshiach is a reward for our work during the era of exile, and in that case that's a fair point, since we're supposed to do mitzvos "not in order to receive reward" (Avos 1:3).
However, the Lubavitcher Rebbe zt"l cites in this connection a statement by R. Schneur Zalman of Liadi (Tanya, ch. 37) that the extent of the revelation of G-dliness that will occur in the time of Moshiach depends on our service of G-d during the era of exile. In other words, as the Rebbe puts it, these bear the same relationship to each other as the planting of a seed does to the growth of the fruit. Isn't it only logical, then, that we do our "planting" with the expectation that it will yield that "fruit"? (The more so because there are aspects of Torah and mitzvos themselves that await the era of Moshiach to be fully realizable in practice, meaning in effect that the "fruit" itself includes the ability to do more mitzvos, much like "learning in order to teach" and "learning in order to perform" (Avos 4:5).)
Indeed, the Rebbe goes on to say that this interdependency is reflected in the names of the two (usually combined) parshiyos of Tazria-Metzora: the "sowing" (tazria) has to be imbued with the idea that it leads not just to something in the indefinite future (zos tihyeh - "this will be" - an older name for Parshas Metzora) but directly to Moshiach (represented as a metzora, as per Sanhedrin 98b (חיוורא דבי רבי שמו) and as explained in Chabad Chassidus (e.g., Likkutei Torah, Vayikra 22b ff)).
This idea is brought in the Rambam Hilchot Tshuvah 3:4
... לפיכך צריך כל אדם שיראה עצמו כל השנה כולה כאילו חציו זכאי וחציו חייב. וכן כל העולם חציו זכאי וחציו חייב. חטא חטא אחד, הרי הכריע את עצמו ואת כל העולם כולו לכף חובה וגרם לו השחתה. עשה מצוה אחת, הרי הכריע את עצמו ואת כל העולם כולו לכף זכות וגרם לו ולהם תשועה והצלה, שנאמר: "וצדיק יסוד עולם" (משלי י, כה). זה שצדק הכריע את כל העולם לזכות והצילו.
...Accordingly, throughout the entire year, a person should always look at himself as equally balanced between merit and sin and the world as equally balanced between merit and sin. If he performs one sin, he tips his balance and that of the entire world to the side of guilt and brings destruction upon himself.
[On the other hand,] if he performs one mitzvah, he tips his balance and that of the entire world to the side of merit and brings deliverance and salvation to himself and others. This is implied by [Proverbs 10:25] "A righteous man is the foundation of the world," i.e., he who acted righteously, tipped the balance of the entire world to merit and saved it.
With this Rambam in mind - it becomes very relevant to connect the act of a mitzvah to the coming of Mashiach - as it may very well be that this particular mitzvah is the very mitvah which will be the 'Makeh b'patish' - to bring Moshiach.
The Lubavitcher Rebbe quoted this Rambam in this context on many occasions.
Alternatively the source of the Moshach times could be from here:
In a sicha on Chayei Sara 5752 (Seif 14) - [Original Yiddish / Hebrew Translation while addressing in particular the Shluchim [at the annual kinus hashluchim] - the Lubavitcher Rebbe stated that all our work in spreading Juduism..should be permeated with the ideal that this hastens Mashiach's coming.
In connection with his exhortation that Jews perform Mitzvot specifically with the intention of hastening the arrival of Mashiach, the Lubavitcher Rebbe often quotes the Mishna, in Brachot 1:5 :
מזכירין יציאת מצרים בלילות. אמר רבי אלעזר בן עזריה, הרי אני כבן שבעים שנה, ולא זכיתי שתאמר יציאת מצרים בלילות, עד שדרשה בן זומא יח, שנאמר "למען תזכר את יום צאתך מארץ מצרים כל ימי חייך" (דברים טז, ג). ימי חייך, הימים. כל ימי חייך, הלילות. וחכמים אומרים, ימי חייך, העולם הזה. כל (ימי חייך), להביא לימות המשיח.
Numerous examples exist. Here is one, from Hitva'aduyot 5792, Vol 1, Page 320.
A search on www.otzar770.com for the phrase "להביא לימות המשיח" will turn up many other results as well, but the texts are stored graphically there, which makes it difficult to copy quotations from there into here.
It seems just the opposite from the gemara in Sanhedrin 97 .The Chachamim were trying to calculate when mashiach will come ,Rav Zeira said please stop pushing away mashiach for three things come when one does not contemplate them Mashiach,an aveidah,and a scorpion.
From this gemarah it seems one should not think how masahiach is going to come.This is not a contradiction to the ani mamims because that is we believe he can come at any moment.