2 shell scripts in Sun Solaris

Hi,
Can somebody pls help me? I need to write 2 shell scripts in Sun Solaris operating system which would do this:

  1. go to the specified directory - I am using alias for it at the moment
  2. start the particular sql script with the output log as same as the script but with timestamp e. g. .dy-m-d.log
  3. when it finishes - echo "script finished successfully"

then I need to do another script little bit similar but with connection to the db:

  1. go to the specified directory - I am using alias for it at the moment as well
  2. start the particular sql script with output log as same as the script but with timestamp e. g. .dy-m-d-a.log
  3. when it finishes with the count=0 exit
  4. when it finishes with the count>0 connect to the db
  5. execute command:....
  6. after it finishes disconnect from the db and start the script in the step 2. but with .dy-m-d-b.log
  7. after it finishes echo "count from 1st script and the second script"

I would appropriate your help as I am new to the shell scripting and still learning.

Thanks in advance

Your question is too broad, and we generally don't write entire scripts from spec (unless it's just a few lines). Check out this link for a very good intro for beginners on shell scripting. It's linux based, but most of this should apply to any modern *NIX.

for logging.... ( i sense some deja vu going here... )
my preferred idiom, subshell with redirection:


date '+%d-%m-%Y | read date_stamp

FLOG=${0##*/}.${date_stamp}

(
echo starting $0 . . . .
some commands
more commands
etc...
) > $FLOG 2>&1

echo all done with $0

Just adding to what Quirky said to help you with your second part. It would be:

FLOG=${0##*/}.${date_stamp}-a.log

{ 
   do-process-part-a
} > $FLOG 2>&1

FLOG=${0##*/}.${date_stamp}-a.log
{
  do-process-part-b
} >$FLOG 2>&1

echo Finished with $0

thanx guys it helped :slight_smile: