LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   run commands in remote machine (https://www.linuxquestions.org/questions/linux-software-2/run-commands-in-remote-machine-518862/)

lhrt 01-13-2007 12:43 AM

run commands in remote machine
 
hi,

Iam using redat EL4. I want to do run some commands on a remote machine using ssh through a script. I already setup ssh-keygen and all so that ican run some commands using cronjob. Now i want to create database ( postgreqsl) in remote machine at a predfined time.

The commands to executed on remote machine are

#service postgresql restart
#su postgres
$dropdb testatabase
$psql testdatabase
$\i testdatabase.sql
$\q
$ctrl+d

how can i do that. please advice.

thanks
Lhrt

osdeals 01-13-2007 01:17 AM

Just put in all the commands into a file (shell script).
eg:

#vi /root/myscript.sh

#!/bin/sh
service postgresql restart
## Put any other commands here
su - postgres
## Put your postgresql commands here
exit

chmod the script to make it executable

#chmod -v 700 /root/myscript.sh

and use ssh as you normally would, except that you append the scriptname after the ssh command.

#ssh machinename /root/myscript.sh

That should do the trick.

Hope that helps.

lhrt 01-13-2007 08:09 AM

thanks man...


All times are GMT -5. The time now is 12:56 PM.