The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
ls command in Remote Server vasuarjula Shell Programming and Scripting 6 06-08-2008 08:11 AM
ls -ltr command On Remote server vasuarjula Shell Programming and Scripting 2 06-01-2008 06:55 AM
ls command in Remote Server vasuarjula AIX 0 05-30-2008 06:22 PM
script working periodically lf398 Shell Programming and Scripting 1 06-10-2006 06:57 PM
remote server command in a job Jimbo Shell Programming and Scripting 2 01-30-2002 11:18 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-16-2008
Registered User
 

Join Date: Nov 2007
Posts: 15
script to send command periodically to remote server

Hi, I'm wondering if there's a way to send a command periodically to remote server through a script.

Right now I have this:
Code:
keepLooping=1
ssh user@domain
while (( keepLooping == 1 ))
do
  echo a
  sleep 3
done
but what this does is ssh to the server, and only when the connection is closed do the following commands run. What I'm trying to achieve is to automate me SSHing to the server and entering a command every xx seconds.

Any suggestions? Thanks!
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 03-16-2008
Wolja's Avatar
Registered User
 

Join Date: Feb 2002
Posts: 15
Quote:
Hi, I'm wondering if there's a way to send a command periodically to remote server through a script.

Right now I have this:

Code:
keepLooping=1
ssh user@domain
while (( keepLooping == 1 ))
do
echo a
sleep 3[/code]
donebut what this does is ssh to the server, and only when the connection is closed do the following commands run. What I'm trying to achieve is to automate me SSHing to the server and entering a command every xx seconds.

Any suggestions? Thanks!
I'm not quite sure what you're trying to do but your while loop is in the wrong place.

Code:
keepLooping=1
while (( keepLooping == 1 ))
do
ssh user@domain
echo a
if [ ?? ] ; then
do something
else
set keeplooping to 1
fi
sleep 3[/code]
Reply With Quote
  #3 (permalink)  
Old 03-16-2008
era
Guest
 

Posts: n/a
If I understand you correctly, you want to run a new ssh command every three seconds, regardless of the fact that the previous ssh command could have taken more than three seconds to complete? So run them in the background.

Code:
while true; do
  ssh user@domain echo a &
  sleep 3
done
The "&" there runs the command in the background.

I assume that "echo a" is the command you want to run on the remote server, and that you had the syntax for this wrong (too).

Unless you are running a real-time operating system, there is no guarantee that "sleep 3" will not take more than 3 seconds, of course.

Edit: Upon rereading your question, I guess that the real problem was really how to pass the remote command to the server over ssh. Well, I coincidentally seem to have answered that, too. If you don't want the ssh to run in the background, just take out the "&".
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 02:35 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0