Operating System - HP-UX
1834009 Members
1866 Online
110063 Solutions
New Discussion

how to check a file on remote machine

 
SOLVED
Go to solution
roberto salvatori
Frequent Advisor

how to check a file on remote machine

hi all,
in a script file, before making a ftpfro a machine 1 to machine 2, i must insert the control if a file exist (ever in a machine 2). which is the best way to control this?
is it better to make a ftp and import on a machine 1 and check if the size is > 0 or create a telnet connection and check the result of the control?
thanks in advice
10 REPLIES 10
Zeev Schultz
Honored Contributor

Re: how to check a file on remote machine

Use remsh $HOST "(file $FILE) or "ls file".

Zeev
So computers don't think yet. At least not chess computers. - Seymour Cray
roberto salvatori
Frequent Advisor

Re: how to check a file on remote machine

i've seen in a previous messages that is possible to check the remsh return code. is it right?
Umapathy S
Honored Contributor

Re: how to check a file on remote machine

rsh, remsh returns the value of their execution and not the remote command return value.

if remsh fails to setup its connection with remote host, then it will flag a failure.

Even if the remote command fails, remsh will always return success only.

To check the remote command status, you may need to redirect the value to a file and check the file.

check the man page for remsh on return value section.

HTH
Umapathy
Arise Awake and Stop NOT till the goal is Reached!
Zeev Schultz
Honored Contributor

Re: how to check a file on remote machine

See that one (for Solaris).
http://www.netsys.com/sunmgr/1997-12/msg00120.html.However I tried and it didn't
work on hp-ux.Should be some way to save remote "$?" - exit status and read it.

Zeev
So computers don't think yet. At least not chess computers. - Seymour Cray
Massimo Bianchi
Honored Contributor

Re: how to check a file on remote machine

Hi,
usually i don't test the ret code for the existance of file, but i count the number of lines in the output and print them.


So

COUNT=$(remsh host -l root -n "ls file" | grep -v "not found" |wc -l )

if $COUNT = 0 -> file does not exists

HTH,
Massimo
Zeev Schultz
Honored Contributor
Solution

Re: how to check a file on remote machine

This one works:

Q: I've been trying to write a script to run a command on a remote machine and determine if the command was successful. However, it always returns 0 regardless of the command's success. What's wrong?

A: Actually, your script is working OK, but the problem is that it isn't what you want. The return code of 0 comes from remsh where 0 means a connection was successful and non-zero means that no connection was possible. remsh does not monitor any command(s) that are sent.

So the solution is to ask the remote system to return the results of executing the remote command. For example:
remsh mymachine 'll /tmp >/dev/null 2>&1 ; echo $?'
will return 0 (ll /tmp was successful) whereas:

remsh mymachine 'll /temp >/dev/null 2>&1 ;echo $?'
will return 1 since ll /temp fails (no such directory). Note also that you should usually use remsh's -n option to avoid hangs when encountering a command or login that requires stdin.

Bless Google :)

So computers don't think yet. At least not chess computers. - Seymour Cray
roberto salvatori
Frequent Advisor

Re: how to check a file on remote machine

thank u so much for all but there is another problem:
if the remote machine who containing the file that i must check is a nt machine? remsh it doesn't work. someone have a solution or ftp is the only way to control?
Zeev Schultz
Honored Contributor

Re: how to check a file on remote machine

Points should go to Bill Hassel :
I found the trick here:
http://www.interex.org/pubcontent/enterprise/nov01/qabh1101.jsp

Zeev
So computers don't think yet. At least not chess computers. - Seymour Cray
Zeev Schultz
Honored Contributor

Re: how to check a file on remote machine

By default,there's no rshd/remshd on win.
Check this link though:
http://www.denicomp.com/rshdnt.htm
So computers don't think yet. At least not chess computers. - Seymour Cray
roberto salvatori
Frequent Advisor

Re: how to check a file on remote machine

thank u Zeev