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