Sponsored Content
Top Forums UNIX for Beginners Questions & Answers How to test if remote dir exist? Post 302986178 by bakunin on Monday 21st of November 2016 12:10:50 PM
Old 11-21-2016
Quote:
Originally Posted by Arnaudh78
It works also,
You will find, that ssh, when executed as a securified rexec-replacement, returns the error code of the remotely executed program.

You could, therefore, equally try the likes of:

Code:
if ! ssh "${user}@${host}" "ls /dir/in/question >/dev/null 2>&1" ; then
     echo "dir does not exist"
else
     echo "dir does exist"
fi

Which would not be of much use in your context (it would i.e. produce false positives if "/dir/in/question" would be a file) but you can use this mechanism to generally execute commands remotely while testing for their return code - UNIX convention is to return 0 on success and something else for the various reasons of being unsuccessful.

I hope this helps.

bakunin
This User Gave Thanks to bakunin For This Post:
 

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Printer Error(the Object Instance Test Does Not Exist)

Hello, i need some help about how to set up a high velocity impact printer in UNIX SCO 5.05, this printer is attached with a parallel port in a PC(host), the host use tunemul to access unix.(this reference is just to ask you if this is a local or remote connection, just to be sure), so, i... (2 Replies)
Discussion started by: jav_v
2 Replies

2. Shell Programming and Scripting

Rsh: test $? on remote system.

Hi, a little help. I need to test the return code of a list file command on a remote system (Unix) using the rsh command. More exactly, to test is a directory exists, I try the following command: rsh $remoteHost "ls -la " $DirRemote Now, if the $DirRemote is not correct and I test... (3 Replies)
Discussion started by: gio123bg
3 Replies

3. Shell Programming and Scripting

To get the dir list of a remote server

Dear all; I am new to UNIX scripting and I want to download remote server's dir listing every hour, to check whether it is updating. How can I do this. can I use ftp command to down load this dir listing. Pls help me in this regards. tks (1 Reply)
Discussion started by: HMS.Chandrasiri
1 Replies

4. Shell Programming and Scripting

File exist test

Can someone please shed light on why this may not be working, file does exist, but I get an error if ] then echo "No ${source_path}/${file_mask} found - ">> ${logfile} result=1 check_result ${result} "Failed to find file... (4 Replies)
Discussion started by: Pokermad
4 Replies

5. Shell Programming and Scripting

How to check whether file is exist on remote server

Hi all, I am new to UNIX Scripting. I would like to know how to check whether file is exist in remote server. I have google, but cannot find any solution that works. Currently my code is like this: if ; then echo 'data file exist' else echo 'data file not exist' fi Thanks in... (3 Replies)
Discussion started by: suigion
3 Replies

6. Shell Programming and Scripting

FNG Question: Test if remote server has booted

Hello again, I have a script on my media server that wakes up my backup server, performs an 'rsync' backup, then shuts the backup server down. Currently, I have it send the Wake on LAN packet, and sleep for 5 minutes, just to give the backup server time to boot (of course it doesn't take that long,... (11 Replies)
Discussion started by: vwgtiturbo
11 Replies

7. Programming

Kernel module - How to test if file doesn't exist

Hey, I'm currently getting into some kernel module progamming. As a little exercise I want to read the headers out of an ELF file. My code is very simple, here is the important part: struct file *fp; /* ... */ fp = filp_open("some/file/on/my/pc", O_RDONLY, 0); if(fp == NULL) { ... (15 Replies)
Discussion started by: disaster
15 Replies

8. Shell Programming and Scripting

Test variables exist using a for loop

I am setting a number of variables in my script and I would like to test they exist by using a for loop. e.g. VAR1=abc VAR2=xyz for i in VAR1 VAR2; do if ; then echo Alert fi done But of course the $i doesn't refer to the variable itself, rather to the strings VAR1 & VAR2. Does... (2 Replies)
Discussion started by: Catullus
2 Replies

9. Solaris

scp from remote dir

Hi Admins, I want to scp some files from remote sub directories.So i used below scripts to accomplish the same. find `ssh testsftp@10.60.5.120/QSYS.LIB/EDWVPINTER.LIB` -name *.MBR -exec scp {} . \; It fails. I can not place copying script in remote server for various reasons. ... (1 Reply)
Discussion started by: newaix
1 Replies
SSH-KEYSIGN(8)						    BSD System Manager's Manual 					    SSH-KEYSIGN(8)

NAME
ssh-keysign -- ssh helper program for host-based authentication SYNOPSIS
ssh-keysign DESCRIPTION
ssh-keysign is used by ssh(1) to access the local host keys and generate the digital signature required during host-based authentication with SSH protocol version 2. ssh-keysign is disabled by default and can only be enabled in the global client configuration file /etc/ssh/ssh_config by setting EnableSSHKeysign to ``yes''. ssh-keysign is not intended to be invoked by the user, but from ssh(1). See ssh(1) and sshd(8) for more information about host-based authen- tication. FILES
/etc/ssh/ssh_config Controls whether ssh-keysign is enabled. /etc/ssh/ssh_host_dsa_key /etc/ssh/ssh_host_ecdsa_key /etc/ssh/ssh_host_rsa_key These files contain the private parts of the host keys used to generate the digital signature. They should be owned by root, read- able only by root, and not accessible to others. Since they are readable only by root, ssh-keysign must be set-uid root if host- based authentication is used. /etc/ssh/ssh_host_dsa_key-cert.pub /etc/ssh/ssh_host_ecdsa_key-cert.pub /etc/ssh/ssh_host_rsa_key-cert.pub If these files exist they are assumed to contain public certificate information corresponding with the private keys above. SEE ALSO
ssh(1), ssh-keygen(1), ssh_config(5), sshd(8) HISTORY
ssh-keysign first appeared in OpenBSD 3.2. AUTHORS
Markus Friedl <markus@openbsd.org> BSD
August 31, 2010 BSD
All times are GMT -4. The time now is 10:59 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy