LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 01-13-2007, 12:43 AM   #1
lhrt
Member
 
Registered: Mar 2006
Posts: 82

Rep: Reputation: 15
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
 
Old 01-13-2007, 01:17 AM   #2
osdeals
Member
 
Registered: Jul 2006
Distribution: RHEL, CentOS, PuppyLinux, SuSe, Ubuntu, Debian
Posts: 59

Rep: Reputation: 15
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.
 
Old 01-13-2007, 08:09 AM   #3
lhrt
Member
 
Registered: Mar 2006
Posts: 82

Original Poster
Rep: Reputation: 15
thanks man...
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to run Graphical commands in remote Desktop. rktech83 Linux - Networking 7 03-09-2006 07:11 AM
Complicated one: MySQL, rsync, remote machine, local machine daiver Linux - General 2 02-27-2006 12:14 PM
bash - execute commands on a remote machine capture results, etc dkrysak Programming 1 11-18-2005 01:50 PM
how to open a dilog on local machine when i do ssh to remote machine fahad26 Programming 3 05-03-2005 07:39 PM
How do I setup xwindow to run a remote desktop on my local machine through ssh. green-ears Linux - Newbie 4 11-04-2003 05:47 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration