I want to go to a particular server for which i have acess .I want to do a ssh to that server from one server and check if a file is theer or not..and i need the script to chcek continuosly till it finds the file.When it finds the file i want it to come out of the loop ..please let me know..
I initially try to do it in my dev server without doing an ssh.
here is what I get..can you help?
./test_new.sh: line 4: ls /home/sendhabh/trial.done 2> /dev/null : No such file or directory
File not found.
-sh-3.2$ ls /home/sendhabh/trial.done
/home/sendhabh/trial.done
-sh-3.2$ wc -l ls /home/sendhabh/trial.done
wc: ls: No such file or directory
1 /home/sendhabh/trial.done
1 total
and this is my script:
-sh-3.2$ more test_new.sh
#!/bin/ksh
while :
do
if [[ $( "ls /home/sendhabh/trial.done 2> /dev/null " | wc -l ) -ne 0 ]]
then
echo "File found."
break;
else
echo "File not found."
sleep 10
fi
done
However for different server shall i remove quotes as well?
now my code looks like this:
-sh-3.2$ ./test_new.sh
File found.
-sh-3.2$ more test_new.sh
#!/bin/bash
while :
do
if [[ -f /home/sendhabh/trial.done ]]
then
echo "File found."
break;
else
echo "File not found."
sleep 10
fi
done
---------- Post updated at 05:27 PM ---------- Previous update was at 04:43 PM ----------
I use this now..howeever i get rror as below:
-sh-3.2$ ./test_GMI_final.sh
ssh: : Name or service not known
File not found.
-sh-3.2$ more test_GMI_final.sh
#!/bin/ksh
DATEPREV=`date --date yesterday "+%d%m%Y"`
while :
do
if [[ $( ssh -n etdmis@$xldn2218pap "ls /sbclocal/InternalSecureFileTransfer/users/ETDIT/gmi_coma/gmi_to_coma/US2COMA_
$DATEPREV.done
2> /dev/null " | wc -l ) -ne 0 ]]
then
echo "File found."
break;
else
echo "File not found."
sleep 10
fi
done
It may not be the wisest thing to do to continuously log in and out the remote system. Why don't you run the loop on the remote server and have it kick off the local action from there?
Pls use code tags as advised!
I don't see an obvious flaw in your script, but it might keep the ssh connection open for hours, which might work on LAN but might be risky for remote conenction across WAN.