Polling for existence of file on remote host


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Polling for existence of file on remote host
# 1  
Old 10-25-2011
Polling for existence of file on remote host

I am polling a file on remote host. I have this code that works, but can't explain why it works.
Code:
while [ -f `ssh user@remote.no-exist.com 'ls /user/app1/.done'` ]
do
  echo [INFO] Sleeping for 5 secs
  sleep 5;
done

This code works in the way that when the .done file exists on the remote host, the script comes out of the while loop. When the .done is not there, it sleeps for 5 secs and checks again.

Reading the code, it seems like if the file exist on the remote host, the ssh will return the path to the file as output with rc=0, which then should get evaluated on local host for existence of a regular file. That file never exists on the local host. I find it strange that it is working and need help in understanding what is making it work. I am on RHEL 5 x86_64.

Thanks in advance!
Smilie

Last edited by Franklin52; 10-26-2011 at 03:30 AM.. Reason: Please use code tags, thank you
# 2  
Old 10-26-2011
Code:
while true
do
  ssh user@remote.no-exist.com 'ls /user/app1/.done' > /dev/null 2>&1
  if [ $? -eq 0 ] ; then
      echo "the job is done"
      exit
  else
     echo [INFO] Sleeping for 5 secs
     sleep 5;
  fi
done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

SFTP file check through a remote host

Hi all, posting my first time, hope not breaking posting rules with it, if yes, let me know. I'm trying to build a script to check a file in an sftp server through a remote server. The intention is to check the file in a sftp host, and if the file is found or not, it should send an email.... (4 Replies)
Discussion started by: MrShinyPants
4 Replies

2. Shell Programming and Scripting

Pause processes in remote host and resume execution in another remote host

Hi, Given addresses of 2 remote machines, using a shell script is it possible to get the state of running processes in "src" stop all the processes in "src" exit out of "src" ssh into "dest" resume the state of executing processes captured in step 1 in "dest" Assumption: "src" is... (3 Replies)
Discussion started by: Saeya Darsan
3 Replies

3. Shell Programming and Scripting

Not able to execute the file in remote host using except utility

I am automating the SFTP keys setp process: So i created the expect script for controlling the output of shell below is my main code: #!/usr/bin/expect set fd set password close $fd set df set app close $df spawn ssh servername << pb Pb file: set df set app close $df (4 Replies)
Discussion started by: Manoj Bajpai
4 Replies

4. Shell Programming and Scripting

Reading file from remote host?

flamingo:~ jnojr$ ssh -t macbook sudo -v Password: Connection to macbook closed. flamingo:~ jnojr$ ssh -t macbook sudo cat /etc/cma.conf | grep CMABuildNumber <CMABuildNumber>2918</CMABuildNumber> Connection to macbook closed. flamingo:~ jnojr$ ssh -t macbook sudo -k Connection to macbook... (3 Replies)
Discussion started by: jnojr
3 Replies

5. Shell Programming and Scripting

Parse file from remote server to calculate count of string existence in that file

Hi I need to parse the file of same name which exist on different servers and calculate the count of string existed in both files. Say a file abc.log exist on 2 servers. I want to search for string "test" on both files and calculate the total count of search string's existence. For... (6 Replies)
Discussion started by: poweroflinux
6 Replies

6. Shell Programming and Scripting

check for file existence on remote machine using sftp

Hi all, I am a beginner to shell script.Can any one please help me on the below requirement I need to check whether the file (called 3Com_Files_Delivered.txt) exists on the remote mechaine or not? if so i need to copy all the files from there to my local mechaine.Especially i am... (7 Replies)
Discussion started by: narasimha123
7 Replies

7. UNIX for Advanced & Expert Users

Help! How to find the local host after few ssh hops to remote host???

I do a ssh to remote host(A1) from local host(L1). I then ssh to another remote(A2) from A1. When I do a who -m from A2, I see the "connected from" as "A1". => who -m userid pts/2 2010-03-27 08:47 (A1) I want to identify who is the local host who initiated the connection to... (3 Replies)
Discussion started by: gomes1333
3 Replies

8. Shell Programming and Scripting

running commands to remote host from centralized host

Gurus/Experts We have a centralized UNIX/Solaris server from where we can actually ssh to all other UNIX/Solaris servers...I need to write a script that reside on this centerlized server and do FileSystem monitoring (basically run df -h or -k) of other remote servers and then send an email to me... (6 Replies)
Discussion started by: anjum.suri
6 Replies

9. Solaris

define .rhost file for tape backup to remote host

howdy experts, i am using 2 server- Solaris 5.9 i have tape device attached with 1 of my solaris server. But others not. # modinfo|grep tape 152 13d43e4 1333c 33 1 st (SCSI tape Driver 1.231) now i want to Backup DATA file and System File in Tape Drive. How do I take data and... (3 Replies)
Discussion started by: thepurple
3 Replies

10. Solaris

How to delete the files from local host to remote host

Hi all, i am copying .gz files from production server to development server using "scp" command.my requirement is after copying .gz files i want to delete old .gz files(two days back) in development server from production server. like this way i need to delelte .log ,.z and .dmp files... (3 Replies)
Discussion started by: krishna176
3 Replies
Login or Register to Ask a Question