Very well done for a first attempt.
You missed your goal, but only by a small margin, here is why, along with some general remarks:
You should not use backticks (`...`), the modern standard is to use the "$(...)" instead. Many still use the old format, but it is not recommended.
The asterisk ("") is a special character to the shell. To use it as a literal character you have to protect it from being interpreted. Usually this is done by surrounding it with quotes: '' or "". It is always a good idea to play it safe in scripts and quote as much as possible. Double quotes protect asterisks and similar chars (wildcards), but do NOT protect dollar signs. Hence, instead of 'typeset filename="ABC"$DATE...' you could surround everything with quotes and write 'typeset filename="ABC${DATE}*"'.
Further, when concatenating such string variables, it is a good idea to use the complete syntax for variables: "$var" is just an abbreviation for "${var}". The former is ok as long as it is (potentially) unambiguous, but the latter is always accurate. Hence, to avoid confusion of the shell (especially when using wildcards) "ABC${DATE}" is better than "ABC$DATE".
At last some personal tips: scripts tend to start out small and become bigger and bigger over time. To write bigger scripts means nothing short of DEVELOPING SOFTWARE and therefore it is a good idea to learn from the software engineers practices - these have basically been developed to help them stay organized in their tons of code. What fits them in their large scale should do for us in our somewhat smaller scale too. It goes beyond the scope of this thread to start a discussion about coding practices (although that would be very interesting), here is just my "personal starter kit of do's and don't's to make life easier":
Always declare your variables. This is not necessary, but a good way to not only keep track of them but also a chance to add a comment about what the variable contains.
Out of personal habit i use prefixes to determine the datatype of a variable: "f" for filenames/directories, "l" for boolean (logical) values, "ch" for characters, "i" for integers. (In fact I use a simplified form of "Hungarian Style Notation".) Of course a shell doesn't know about datatypes and it is possible to use an int value as string, but as soon as you try "if [ $var -gt 100 ]" on a character variable you'd get an error. Staying clear of such confusion avoids these problems.
Talking about variables names: make them speaking! It is a lot easier to type a few characters more than it is to rember what "pidblftx1" is standing for. It is easier to understand the line "if [ $iNextUserID -gt $iMaximumUserID ]" than it would be to read "if [ $nuid -gt $muid ]". More likely than not you will soon forget what "$a", "$A" and "$B" contain, a speaking name is a good way on saving time you would otherwise have to spend on documentation.
Always comment your code. Try to picture yourself in a year from now, having long forgotten what you did today and try to write down for that person what you are doing. I have three standard commenting places: every variable declaration gets a comment telling its content: "typeset -i iUserCnt=0 # counter for user accounts". The next place is the header, before any code starts, with an explanation about what the script does and if it does it in a counterintuitive way why this is so. The third place for comments are code blocks: every group of statements belonging together is commented with a short explanation about what the block does, something like "derive home directory from UID" or so. This makes it easier to navigate between functional entities in the script.
Here is your revised script, it should do now what you want it to do:
#!/bin/ksh
# search for tar files in /backup/exp and print message
typeset chHostName="$(hostname)" # the hosts name
typeset chTimeStamp="$(date +"%y%m%d")" # todays date
typeset fName="" # file name buffer
typeset iErrLvl=0 # exit code: 0=ok
# >0: no tar files
fName="AIDMS_${chHostName}${chTimeStamp}*tar.Z" # put filename together
print - "$0 checking for $fName on $chHostName"
if [ -e /backup/exp/$fName ] ; then
print - "Everything ok, $fName is there"
else
print -u2 "Error: $fName is missing"
(( iErrLvl = 1 ))
fi
exit $iErrLvl
Sorry for this longwinded post, I'm a Mullah in the Sect of Clean Coding and enjoy it deeply to preach about the subject. ;-))
bakunin