script to send command periodically to remote server


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting script to send command periodically to remote server
# 1  
Old 03-17-2008
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!
# 2  
Old 03-17-2008
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]
# 3  
Old 03-17-2008
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 "&".
era
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Run remote command and send email

I am currently try to write a simple script with the following condition, but so far not having luck as the exit code would always be 0. Run remote command to read a file and grep for test word. if test word is in the file, send email. if not, do nothing also possible to ssh to multiple... (3 Replies)
Discussion started by: jaapar
3 Replies

2. Shell Programming and Scripting

Script connect to remote server, not find files and exit only from remote server, but not from scrip

I have a script, which connecting to remote server and first checks, if the files are there by timestamp. If not I want the script exit without error. Below is a code TARFILE=${NAME}.tar TARGZFILE=${NAME}.tar.gz ssh ${DESTSERVNAME} 'cd /export/home/iciprod/download/let/monthly;... (3 Replies)
Discussion started by: digioleg54
3 Replies

3. Shell Programming and Scripting

Check/get the exit status of a remote command executed on remote host through script

Geeks, Could you please help me out in my script and identify the missing piece. I need to check/get the exit status of a remote command executed on remote host through script and send out an email when process/processes is/are not running on any/all server(s). Here's the complete... (5 Replies)
Discussion started by: lovesaikrishna
5 Replies

4. Shell Programming and Scripting

How to Append the output of a script running in remote server to a file in local server?

Hi guys, So i am in server1 and i have to login to server 2, 3,4 and run some script there(logging script) and output its result. What i am doing is running the script in server2 and outputting it to a file in server 2 and then Scp'ing the file to server1. Similarly i am doing this for other... (5 Replies)
Discussion started by: srkmish
5 Replies

5. Solaris

Script to get files from remote server to local server through sftp without prompting for password

Hi, I am trying to automate the process of fetching files from remote server to local server through sftp. I have the username and password for the remote solaris server. But I need to give password manually everytime i run the script. Can anyone help me in automating the script such that it... (3 Replies)
Discussion started by: ssk250
3 Replies

6. HP-UX

Connect to remote server using sftp with password define within command/script

I am trying to connect to remote server in hp-ux, using sftp command (using sftp username@ip and password ) able to connect to remote server but, in this case sftp prompt for password and user need to manually enter it. I want sftp can read a password define in script or from file, so it can... (1 Reply)
Discussion started by: ketanraut
1 Replies

7. Shell Programming and Scripting

Send information about disk occupation periodically by email

Hi, I want to make a shell script that gives me the information about the disk occupation by sending me an email once in a month for example. With this command df|tr -s " "|cut -d" " -f 1,5 I can see the occupation but I dont know how to make the machine to send me the email with this... (7 Replies)
Discussion started by: Adam Brave
7 Replies

8. Shell Programming and Scripting

Need script to run the command in remote server

hi, I need script to perform below task. 1. Read the IP address 2. copy the script from origin server to destination. 3. get root access on destination server 4. run the script on destination server 5. return to the origin server Code: #!/bin/bash echo "Enter Server IP... (5 Replies)
Discussion started by: bapu1981
5 Replies

9. Shell Programming and Scripting

Executing local script/command on remote server

I have a command that I want to run on machine B from machine A. If I run the command on machine B locally, it works fine. Here is the command: for n in `find /data1/ -name 'ini*.ext'` ; do echo cp $n "`dirname $n `/` basename $n .ext`"; done From machine A, I issue this command ... (3 Replies)
Discussion started by: dirtyd0ggy
3 Replies
Login or Register to Ask a Question