nixCraft Linux Forum

nixCraft

Linux Tech Support Forum

Check file exists on Remote Server

This is a discussion on Check file exists on Remote Server within the Shell scripting forums, part of the Development/Scripting category; Hello There, Kind of a newbie to shell scripting - need some help. I need some help with shell script ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 06-11-2008, 11:34 PM
Junior Member
User
 
Join Date: Jun 2008
My distro: Debian
Posts: 2
Rep Power: 0
sanjus is on a distinguished road
Default Check file exists on Remote Server

Hello There,

Kind of a newbie to shell scripting - need some help.

I need some help with shell script to check if the remote server is up & running (i guess i need to use ping) and to check if a particular file (say /home/<user-name>/somefile.txt) exists.

If any of the above 2 conditions are not met then i need to terminate/abort the script.

TIA for all your help,

regards,
sanju
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 06-12-2008, 12:45 AM
Junior Member
User
 
Join Date: Feb 2008
My distro: .
Posts: 10
Rep Power: 0
unSpawn is on a distinguished road
Default

With respect to ping you can find out the commandline to use doing 'man ping'. As far as the remote file check goes, determine what means of access you have, could be anything from SSH to HTTP to SNMP.
Being a "newbie" should not be used as an excuse for not reading stuff like BASH Programming - Introduction HOW-TO and http://www.tldp.org/LDP/Bash-Beginne...tml/index.html
(the http://www.tldp.org/LDP/abs/html/ prolly being a bit too steep). Look only for basic tests and exit codes.
Having read those now you can write some "pseudo code" people can comment on and before you know it you're no newbie no more.
Reply With Quote
  #3 (permalink)  
Old 06-12-2008, 01:09 AM
Junior Member
User
 
Join Date: Jun 2008
My distro: Debian
Posts: 2
Rep Power: 0
sanjus is on a distinguished road
Default

before posting, i did browse the Linux Shell Scripting Tutorial posted on this forum - however, i did not find any reference to check files (or for that matter conditional checking) on remote servers.

The servers do have ssh access and i would like to do real-time checking just like we do on local server (if [-f <file-name>] ... ) rather than ftping the file back & forth.

something: if [-f ssh remote-server:/home/<user-name>/filename ] ... )

thanks.
Reply With Quote
  #4 (permalink)  
Old 06-12-2008, 06:05 AM
Junior Member
User
 
Join Date: Feb 2008
My distro: .
Posts: 10
Rep Power: 0
unSpawn is on a distinguished road
Default

ping -c 1 ipaddress && ssh user@host 'test -e /path/and/filename && echo exists'
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

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

Similar Threads

Thread Thread Starter Forum Replies Last Post
forced file check fsck smr36 Ubuntu / Debian 3 04-16-2008 09:23 AM
Shell script to check the disk space on remote systems vijayscripts Shell scripting 5 10-21-2007 06:29 PM
Command to Check Linux File System lacloai Getting started tutorials 3 05-14-2007 05:45 PM
script on how to check if the file exists warren Shell scripting 4 04-14-2006 05:51 PM
freebsd ifconfig alias up ioctl siocaifaddr file exists erro ZigZag All about FreeBSD/OpenBSD/NetBSD 1 12-23-2005 04:49 PM


All times are GMT +5.5. The time now is 06:40 PM.


Powered by vBulletin® Version 3.7.3 - Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36