Redirecting output of a command to a file

Hi

We are having a requirement where one shell script, say a.sh (which uses Java and connects to Oracle database using JDBC) keeps on running everytime. I created a wrapper (to check whether a.sh is running and if not then to start it) and scheduled it in the crontab. Now all the output from this script gets written to the mail file of the user.

To avoid the whole stuff being written to the mail file, i thought about re-directing the same to some log files (generated on the daily basis). I tried this:

#!/bin/sh
a=`ps -ef|grep repgen.sh|grep -v grep|wc -l`
b=`/usr/bin/date +"%d%m%y"`
if [ $a -lt 1 ]; then
sh /dit/scheduler/bcp/repgen.sh 1>>/dit/scheduler/bcp/$b.log1 
2>>/dit/scheduler/bcp/$b.log2
fi

But now the issue is, if a.sh keeps on running without any issues, wrapper doesn't find anything to do and the the output keeps on getting appended to the very first logfile (logfile when first time a.sh started). Is there a possible way out so that i can generat logs in files created for everyday.

Thanks & Regards
Ankit Goel

hi,
why don't add a else to your script?
Bye

Hi
Suppose that the code is written in the file a.sh.
Now the crontab has a entry

          • /dit/scheduler/bcp/a.sh
            Every minute it checks whether a.sh is running or not.

Now suppose that the the wrapper started today.The log file name will be
130409.log1.Now i want that the next day i.e tomorrow the log file should be generated with the name 140409.log1.

Thanks & regards
Ankit Goel

Try this:

command >> $(date '+%d%m%y').log1

Regards