Operating System - HP-UX
1752797 Members
5992 Online
108789 Solutions
New Discussion юеВ

Remote Command To Check File

 
SOLVED
Go to solution
Acxiom Unix Team
Frequent Advisor

Remote Command To Check File

Hi,

I am trying to work out some script to check for the existence of a file on a remote box. This will be run as a pre-exec job by some maestro jobs. And depending on the results, depends if the job then submits the main job or not.

I need to get 3 results though;

1) Cannot i firstly remsh to the server?
2) If i can, is the file there? Yes or No?

I have attached a copy of what i thought might work but i seem to hit some problems. I have sent all output to a text file so i can see what i am getting back.

When the file exists i get the response to say it has found it. However, if i change the name of the file its looking for, i still get the same response saying it has found it.

So if anyone has any good tips/tricks on how i can get this script to work that would be great.

Thanks
Where is my beer...??
2 REPLIES 2
James R. Ferguson
Acclaimed Contributor
Solution

Re: Remote Command To Check File

Hi Andrew:

You could do something as simple as:

# cat ./queryit
#!/usr/bin/sh
typeset HOST=$1
typeset FILE=$2
remsh ${HOST} -n "[ -f ${FILE} ] && echo ${FILE} found || echo ${FILE} missing" 2>/dev/null
[ $? = 0 ] || echo "${HOST} wasn't available"
exit

...run as :

# ./queryit mybox myfile

Notice that I used 'remsh' per your request. A more secure way would be to substitute 'ssh' for 'remsh' and thus use a secure shell connection.

Regards!

...JRF...
Acxiom Unix Team
Frequent Advisor

Re: Remote Command To Check File

JRF,

Brilliant, thanks for that. Exactly what we need.....

Andy
Where is my beer...??