Continuous checking of a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Continuous checking of a file
# 1  
Old 01-23-2013
Continuous checking of a file

I have a requirement like this...


I want to go to a particular server for which i have acess .I want to do a ssh to that server from one server and check if a file is theer or not..and i need the script to chcek continuosly till it finds the file.When it finds the file i want it to come out of the loop ..please let me know..
# 2  
Old 01-23-2013
Code:
#!/bin/ksh

while :
do
        if [[ $( ssh -n ${user}@${host} "ls filename 2> /dev/null " | wc -l ) -ne 0 ]]
        then
                echo "File found."
                break;
        else
                echo "File not found."
                sleep 10
        fi
done

# 3  
Old 01-23-2013
hi Bipin,

thanks forthat.

I initially try to do it in my dev server without doing an ssh.

here is what I get..can you help?


Code:
./test_new.sh: line 4: ls /home/sendhabh/trial.done  2> /dev/null : No such file or directory
File not found.
-sh-3.2$ ls /home/sendhabh/trial.done
/home/sendhabh/trial.done
-sh-3.2$ wc -l ls /home/sendhabh/trial.done
wc: ls: No such file or directory
1 /home/sendhabh/trial.done
1 total

and this is my script:

Code:
-sh-3.2$ more test_new.sh
 #!/bin/ksh
while :
do
        if [[ $( "ls /home/sendhabh/trial.done  2> /dev/null " | wc -l ) -ne 0 ]]
        then
                echo "File found."
                break;
        else
                echo "File not found."
                sleep 10
        fi
done


Last edited by Scrutinizer; 01-23-2013 at 03:33 AM.. Reason: code tags
# 4  
Old 01-23-2013
You should not use double quotes here. Alternatively try
Code:
if [ -f /home/sendhabh/trial.done ]; then

# 5  
Old 01-23-2013
That worked.Thanks bipin.

However for different server shall i remove quotes as well?

now my code looks like this:

Code:
-sh-3.2$ ./test_new.sh
File found.
-sh-3.2$ more test_new.sh
 #!/bin/bash
while :
do
        if [[ -f /home/sendhabh/trial.done ]]
        then
                echo "File found."
                break;
        else
                echo "File not found."
                sleep 10
        fi
done

---------- Post updated at 05:27 PM ---------- Previous update was at 04:43 PM ----------

I use this now..howeever i get rror as below:

Code:
-sh-3.2$ ./test_GMI_final.sh
ssh: : Name or service not known
File not found.


Code:
-sh-3.2$ more test_GMI_final.sh
#!/bin/ksh
DATEPREV=`date --date yesterday "+%d%m%Y"`
while :
do
        if [[ $( ssh -n etdmis@$xldn2218pap "ls /sbclocal/InternalSecureFileTransfer/users/ETDIT/gmi_coma/gmi_to_coma/US2COMA_
$DATEPREV.done
 2> /dev/null " | wc -l ) -ne 0 ]]
        then
                echo "File found."
                break;
        else
                echo "File not found."
                sleep 10
        fi
done


Last edited by Scrutinizer; 01-23-2013 at 05:30 AM.. Reason: code tags; code tags again
# 6  
Old 01-23-2013
It may not be the wisest thing to do to continuously log in and out the remote system. Why don't you run the loop on the remote server and have it kick off the local action from there?
# 7  
Old 01-23-2013
I use this now and it works..


Code:
#!/bin/bash
DATEPREV=`date --date yesterday "+%d%m%Y"`
ssh xldn2218pap << MSH
while :
do
if [ -f /sbclocal/InternalSecureFileTransfer/users/ETDIT/gmi_coma/gmi_to_coma/US2COMA_$DATEPREV.done ] ;
then
 echo "File found."
 break;
else
               echo "File not found."
                sleep 300
        fi
done
MSH


does it look good rudiC and bipin?

Last edited by Scrutinizer; 01-23-2013 at 07:07 AM.. Reason: code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Continuous for loop

Hi All, Please help ***************** a=100 and run for loop that will minus 30 from 100 an will display value run loop will run till display value will be 0 ***************** Thanking you (1 Reply)
Discussion started by: Praful Pednekar
1 Replies

2. Shell Programming and Scripting

Continuous Copying from a directory to another.

Hello Folks, Looking for a script, where i can check for the existing of the files in a directory and copying to another. How can i achieve it in loop for over period of time. whatever files comes into the folder copied in another without duplicate and should be continuous loop. ... (8 Replies)
Discussion started by: sadique.manzar
8 Replies

3. Shell Programming and Scripting

Detect continuous number as range

I have 100k data like this bellow , i want to group data to range 171 172 173 174 175 176 179 182 183 187 188 189 1900 1901 1903 1904 1905 1906 (10 Replies)
Discussion started by: before4
10 Replies

4. Shell Programming and Scripting

Creating a Continuous File Reading-Executing Shell Script

I need to write something that will read and execute all the files(Mainly executable scripts) inside one or more folders; in other words, a continuous chain with a break when finished. I'm new to shell and need syntax help. I'm on Ubuntu 12.10-Gnome btw. Here are some main highlights I think... (2 Replies)
Discussion started by: linuxlololol
2 Replies

5. Shell Programming and Scripting

Continuous log file transfer to remote server

I have several production servers and 1 offline server. Production server continuously generates new log files for my application. Depending on time of day new files may be generated every few seconds and at other times every few hours. I also have an offline server where I would like to pull log... (3 Replies)
Discussion started by: yoda9691
3 Replies

6. Shell Programming and Scripting

Rename files with continuous numbers

I have a huge collection of HTML files. They have their own file names with htmlextension. I want to rename each of these files with continuous numbers starting from 1.html till the last count of files. Simply it means that if there are three files like this abc.html cdfhg.html rmbd.htmlthen... (1 Reply)
Discussion started by: shoaibjameel123
1 Replies

7. Shell Programming and Scripting

Continuous Flat file parsing

Hi all, I'm looking for some tips on an ideal method of parsing a huge fixed length flat file (~500gb) into a delimited text file. We have to do this because our data warehouse platform only accepts delimited file loads. In the past, we've done this with SAS (only on smaller ~40GB files) by... (1 Reply)
Discussion started by: cg2
1 Replies

8. Shell Programming and Scripting

Removing dupicate lines in the file ..(they are not continuous)

I have duplicates records in a file, but they are not consecutive. I want to remove the duplicates , using script. Can some one help me in writing a ksh script to implement this task. Ex file is like below. 1234 5689 4556 1234 4444 (7 Replies)
Discussion started by: Srini75
7 Replies
Login or Register to Ask a Question