Linux / UNIX Tech Support Forum
This is a discussion on Check if remote files exist (periodically) within the Shell scripting forums, part of the Development/Scripting category; Hi all, I am trying with next code to check file existence from time to time Code: while [ 1 ...
|
|||||||
| Shell scripting You can discuss the shell scripting, request shell scripts and scripting techniques |
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
Hi all,
I am trying with next code to check file existence from time to time Code:
while [ 1 ]
do
if [ ssh ${REMOTE_USER}@${REMOTE_HOST} 'ls "'$RESULT_FILE'" >/dev/null' ]; then
echo "file $RESULT_FILE exists";
exit;
break;
else
echo "file $RESULT_FILE does not exist";
sleep 5
fi
done
When I tried to create $RESULT_FILE in the remote machine and the code still running, it always give me a false indication about the file even the actual file exist! CASE II When I tried to delete the remote file, the code above gives me again a false indication about the file by saying the remote file exists which no exist in reality I hope if someone can help me with this problem Thanks in advance. |
| Sponsored Links | ||
|
|
|
||||
|
SSH is not designed for this kind of work. It will never work out. You need to use ftp or something else using Perl / Python. FTP would be easy to script and can perform various operations such as rename, delete, upload, download and so on.
__________________
Vivek Gite Linux Evangelist |
|
|||
|
not to knock the person that responded, but with linux you can do almost anything you want to if you put some pieces together.
for your instance, you want to use grep. grep is your friend. since grep uses a 0 or 1 on exit, 0 if it finds something or 1 if it doesnt, you could do something like this.... Code:
CHECKFILE=`ssh <user>@<host> 'ls /path/to/file | grep file > /dev/null; echo $?'` if [ $CHECKFILE -eq 0 ] then echo "file exists" else echo "file doesnt exist" fi i hope this helps Last edited by nixcraft; 28-02-2009 at 11:59 AM. |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) |
|
| Thread Tools | |
| Display Modes | |
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Unix Shell: Check if Word exist in file or not | LinuxCommandos | Shell scripting | 1 | 07-11-2008 02:50 AM |
| Check file exists on Remote Server | sanjus | Shell scripting | 3 | 12-06-2008 06:05 AM |
| Checking files exist | seeker082 | Shell scripting | 6 | 22-02-2008 12:39 AM |
| Shell script to check the disk space on remote systems | vijayscripts | Shell scripting | 5 | 21-10-2007 06:29 PM |
| shell script to open log files and check for faults | trueman82 | Shell scripting | 1 | 23-11-2006 02:35 AM |