I am stuck varying an action. This is the action $$S=\int\mathrm d^{4}x \frac{a^{2}(t)}{2}(\dot{h}^{2}-(\nabla h)^2)$$
And this is the solution, $\ddot{h} + 2 \frac{\dot{a}}{a}\dot{h} - \nabla^{2}h $.
This is what I get $$\partial_{0}(a^{2}\partial_{0}h)-\partial_{0}(a^{2}\nabla h)-\nabla(a^{2}\partial_{0}h)+\nabla^{2}(ha^{2})$$ I don't really see my mistake, perhaps i am missing something. (dot represents $\partial_{0}$)
It is this problem (see Lectures on the Theory of Cosmological Perturbations, by Brandenburger)
$\quad$To quadratic order in the fluctuating fields, the action separates into separate terms involving $h_+$ and $h_x$. Each term is of the form $$S^{(2)}=\int\mathrm d^4x\dfrac{a^2}{2}\left[h'^2-(\nabla h)^2\right]\,,\tag{91}$$lading to the equation of motion $$h_k''+2\dfrac{a'}{a}h_k'+k^2h_k=0\,.\tag{92}$$ The variable in terms of which the action $\text{(91)}$ has canonical kinetic term is $$\mu_k\equiv ah_k\,,\tag{93}$$ and its equation of motion is $$\mu_k''+\left(k^2+\dfrac{a''}{a}\right)\mu_k=0\,.\tag{94}$$
Going from step 91 to 92
Varying the action we find the Euler-Lagrange equation of motion $$\frac{\partial}{\partial x^\mu} \frac{\partial \mathcal{L}}{\partial (\partial_\mu h)} = \frac{\partial \mathcal{L}}{\partial h}$$ or $$\frac{\partial}{\partial t} \frac{\partial \mathcal{L}}{\partial \dot h} - \frac{\partial}{\partial x^i} \frac{\partial \mathcal{L}}{\partial (\partial_i h)} = \frac{\partial \mathcal{L}}{\partial h},$$ where $$\mathcal{L} = \frac{1}{2} a(t)^2 \left(\dot h^2 - (\nabla h)^2\right)$$ is the Lagrangian (also called the Lagrangian density). Boundary terms can typically arise but are here ignored on physical grounds.
We find $$\begin{eqnarray*} \frac{\partial}{\partial t}\frac{\partial \mathcal{L}}{\partial \dot h} &=& \frac{\partial}{\partial t}(a^2 \dot h) \\ &=& a^2\ddot h + 2 a \dot a \dot h \\ \frac{\partial}{\partial x^i}\frac{\partial \mathcal{L}}{\partial (\partial_i h)} &=& \frac{\partial}{\partial x^i}(a^2 \partial_i h) \\ &=& a^2 \nabla^2 h \\ \frac{\partial \mathcal{L}}{\partial h} &=& 0. \end{eqnarray*}$$ Therefore, $$a^2 \ddot h + 2 a\dot a \dot h - a^2 \nabla^2 h = 0.$$ Dividing by $a^2$ we find the claimed result, $$\ddot h + 2 \frac{\dot a}{a} \dot h - \nabla^2 h = 0.$$