one="/home/myuser"
file1=$one/file1.txt
if [ -f $file1 ]
then
echo "Present"
else
echo "Not present"
fi
# sh test.sh
Not present
# touch /home/myuser/file1.txt
# sh test.sh
Present
EDIT: Oh my bad on a remote machine??? Are you using nfs to mount the directory? You will need to connect to the remove machine some how, nfs, samba, ssh, etc.....
I have created two scripts, one with hardcoded and another one with extract from file instead of hardcoded,
script:1
--------
#!/bin/ksh
filename="$one/file1.dat"
if [ -f $filename ]
then
echo "$filename has arrived." >> $logfile
else
echo "$filename has NOT yet arrived." >> $logfile
fi
:>
Result:
$one/file1.dat has arrived.
script:2
--------
#!/bin/ksh
outfile=$HOME/outputfile.lst
splitfile=$HOME/splitfile.lst
infile=$HOME/inputfile.lst
rm -f $infile
rm -f $splitfile
rm -f $outfile
sqlplus -s << sqlEOF
$user/$pass
whenever sqlerror exit 1
set head off pages 0
set feedback off
spool $infile
SELECT files
FROM tab1;
spool off
sqlEOF
cat $infile | while read filename time
do
checkfile=$filename
echo $checkfile,$filename >> $splitfile
if [ -f $checkfile ]
then
echo "$checkfile has arrived." >> $logfile
else
echo "$checkfile has NOT yet arrived." >> $logfile
fi
done
outfile shows,
$one/file1.dat has NOT yet arrived.
$one/file2.dat has NOT yet arrived.
$two/file1.lst has NOT yet arrived.
$two/file2.lst has NOT yet arrived.
Here those above files are presents in UNIX directory still it shows NOT yet received and the same is working for script 1 (hardcoded with one single file) and script 2 is NOT working.