Execute scripts from remote using telnet

Hi

having the below code

(sleep 1 echo "username"
 sleep 2 echo "password"
 sleep 2 echo "cd /home/test1/path"
 sleep 10 echo "ls -l | grep filename"

if exists
echo "script1.sh filename"
echo "mailx -s "Task Executed" user@domain.com"
else 
echo "mailx -s "File not Exist" user@domain.com"

echo "exit" ) | telnet server1 

Need to know wat kind of condition statement to use for this scenario.

Thanks with anticipation

You can use if [ -x ./script1.sh ] to test whether it is present and executable.