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:
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.
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]
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.
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 "&".
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)
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)
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)
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)
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)
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)
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)
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)
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)