The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
check if file exists on remote system ? hcclnoodles Shell Programming and Scripting 2 10-26-2006 04:08 AM
Need Script to check whether user exists in the remote machine Srini75 SCO 1 09-07-2005 11:23 AM
check if exists a .ZIP file and unzip it using ftp DebianJ Shell Programming and Scripting 1 05-05-2005 04:46 PM
Check Remote Folder Exists borncrazy Shell Programming and Scripting 1 07-12-2004 04:15 PM
perl ftp check file exists methos Shell Programming and Scripting 2 06-18-2003 08:21 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-29-2007
hcclnoodles hcclnoodles is offline
Registered User
  
 

Join Date: Mar 2002
Posts: 272
check if remote file exists

Hi

Does anybody know how I can check if a file exists on a remote machine

i.e. see bellow, this doesn't work by the way and if tried countless variations on this


Code:
#!/bin/sh

hostname=server56

if [ -f `ssh $hostname '/usr/local/file'` ]; then
echo file exists
else
echo file doesn't exist
fi
Any help on this would be greatly appreciated
  #2 (permalink)  
Old 06-29-2007
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,416
One way (not tested):

Code:
#!/bin/sh

hostname=server56

if [ -n `ssh $hostname 'ls /usr/local/file 2>/dev/null'` ]; then
echo file exists
else
echo file doesn't exist
fi
  #3 (permalink)  
Old 08-27-2008
mikemark mikemark is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 2
Here's another way:

Code:
#!/bin/sh

#
# Name:
#       testfile
#
# Usage:
#       ./testfile "/dir/and file to test for.txt"
#
# Notes:
#       Quotes needed when testing for names with whitespace, etc.
#       Be certain to:
#               > chmod 700 testfile
#       and perform any setup needed for ssh such as key generation and
#       proper placment on the remote computer
#

hostname=mike@ram

echo $hostname
if ssh $hostname 'ls "'$1'" >/dev/null'; then
        echo "file '"$1"' exists";
        echo "byebye";
        exit;
else
        echo "file '"$1"' doesn't exist";
fi
echo "finito!"
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:19 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0