Making a KSH exit if path is not correct

I am very green to shell programming and have no training and this is my first real attempt. I am fairly versed in Unix and running the cmds I need. I tried using the search feature but most of what I found was close but not quite what I am looking for, plus most looked more advanced than I understand. Basically I am trying to automate a process for our support team to pass two parameters to my script, the first specifies which directory it needs to reside. My problem is if they put the wrong dir then I want it to fail, as it stands now I can put anything in and it just runs through to completion and does what it can. Posting my very simple rudimentary code below.

#! /usr/bin/ksh
set -x
host=`hostname`
pk=agent_$host
#This will put user in Tidal Directory#
cd /opt/$1/Agent
##################################################
# This Will Tar all agent logs#
tar -cvf $pk.tar *
##################################################
# This Will gzip agent logs
gzip $pk.tar
##################################################
# This will move file out of agent dir to /tmp to not fill filesystem#
mv $pk.tar.gz /tmp
##################################################
# This will stop and start the agent#
cd /opt/$1/Agent/bin
tagent tidal_agent_$2 stop
sleep 30
####################################################
# tagent tidal_agent_1 start
# This will send mail letting us know agent was restarted#
#####################################################
( echo Agent $host has been restarted )| mailx -s "Logs have been tared on Agent `$host'`" clintbateman@comcast.net
exit

Hi.

You can test for the directory using something like:

if [ ! -d /opt/$1/Agent ]; then
  echo "Directory does not exist"
  exit 1
fi

First you should check the you have all the arguments you need:

if [ $# -ne 2 ]; then
  echo "Usage:  ......."
  exit 0
fi
if [[ ! -d /opt/$1/Agent ]] ; then
  echo "bad parameter: directory /opt/$1/Agent not found."
  exit 1
fi

Is that what you need?

Thank you both, exactly what I needed, I need something for $2 also but I think I can figure it out with this.

---------- Post updated at 09:07 AM ---------- Previous update was at 08:53 AM ----------

Ok maybe one more.

# This will stop and start the agent#
cd /opt/$1/Agent/bin
tagent tidal_agent_$2 stop
sleep 30

If $2 is passed incorrectly I would get this message running the command

*** Agent Instance not defined in the ini file

How could I also make it exit if my process does not start?

I don't know anything about your agent, but does it return a non-zero exit code after you start or stop it and there's an error?

tagent tidal_agent_$2 stop
if [ $? -ne 0 ]; then
  echo "Error stopping agent $1"
  exit 2
fi

No it only gives the output

*** Agent Instance not defined in the ini file

It does not pass a return code

tagent tidal_agent_$2 stop 2 >&1 | grep -q 'Agent Instance not defined in the ini file'
if [[ $? -ne 0 ]] ; then
   echo "agent start failed"
else
   echo "agent started"
fi

I did not use the second echo just made it exit but that was exactly what I needed. Thanks for the assistance.