It's a Shanti Mantra that occurs in the beginning of chapter 3 of the Taittiriya Aranyaka of the Yajur Veda (as you can see here):
gātuṃ yajñāya |
gātuṃ yajñapataye |
daivī svastirastu naḥ |
ūrdhvaṃ jigātu bheṣajaṃ |
śaṃ no astu dvipade |
śaṃ catuṣpade |
oṃ śānti śānti śāntiḥ ||
It also occurs in a Khila Sukta in Mandala 10 of the Rig Veda, as you can see here. In any case, it's commonly recited as a Shanti mantra before reciting the Purusha Sukta, a famous Vedic hymn in praise of Vishnu. Here is the meaning:
We worship and pray to the Supreme Lord for the welfare of all beings. May all miseries and shortcomings leave us forever so that we may always sing for the Lord during the holy fire ceremonies. May all medicinal herbs grow in potency so that all diseases may be cured. May the gods rain peace on us. May all the two-legged creatures be happy, and may all the four-legged creatures also be happy. May there be peace in the hearts of all beings in all realms.
And here is the Anukramani information for this mantra:
Sage Shamyu is the seer. Shakvari is the metre. Vishvadeva or cosmic spirits are the presiding deities; for everlasting peace is this affirmation.
The story of the sage Shamyu Barhaspatya and how he heard this mantra is told in this chapter of the Shatapatha Brahmana of the Yajur Veda:
Thereupon he pronounces the 'All-hail and blessing' (sam-yos). Now it was Samyu Bârhaspatya who perceived, in its true nature, the consummation of the sacrifice. He went to share in the world of the gods. Thereupon that (knowledge) was entirely lost to men. It then became known to the Rishis, that Samyu Bârhaspatya had perceived, in its true nature, the consummation of the sacrifice, and had gone to share in the world of the gods. By pronouncing the samyoh, they attained to that same consummation of the sacrifice which Samyu Bârhaspatya had perceived; and to that same consummation of the sacrifice, which Samyu Bârhaspatya had perceived, this (Hotri) attains by pronouncing the sam-yoh. For this reason he pronounces the 'All-hail and blessing.' He intones, 'We long for that All-hail and blessing (sam-yoh);' whereby he says, 'We long for that consummation of the sacrifice which Samyu Bârhaspatya perceived.'
'Success to the sacrifice, success to the lord of sacrifice!' he who wishes for the consummation of the sacrifice, thereby wishes success to the sacrifice and success to the lord of sacrifice.--'Bliss (svasti) to us, bliss to men!' he thereby says, 'May we enjoy bliss among the gods, bliss among men!'--'May the means of salvation ascend on high!' he thereby says, 'May this sacrifice secure for us the world of the gods!' 'All-hail, for us, to the two-footed, all-hail to the four-footed!' for so far as the two-footed and the four-footed (extend), so far does this universe (extend). Having now attained the consummation of the sacrifice, he bids All-hail to this (sacrificer), and for this reason he says, 'All-hail, for us, to the two-footed, all-hail to the four-footed!'
The ritual being described, where this mantra is chanted, is known as the Shamyuvaka, and it's a Shanti ritual done during Vedic Yagnas.