Shell script automation using cron which query's MySQL Tables

What I have:

I have a input.sh (script which basically connect to mysql-db and query's multiple tables to write back the output to output1.out file in a directory)

note: I need to pass an integer (unique_id = anything b/w 1- 1000) next to the script everytime I run the script which generates output file by that integer I passed (output1.out, output2.out .... etc....)

I simply run this command now: sh input.sh 88 |mysql -h XXXX -u XXXX -p XXXX ---> this writes back the output(output1.out) file to a location.

What I require:

I want to write a wrapper script and schedule with a cron job --

to run this script daily with multiple unique_id's at once and writes out the output files with respective unique_id numbers ( output1.out, output2.out etc..) and send the resulting output file (output1.out) as an attachment to an email distribution list..

The format of the output file should: more manageable, for example, the email recipients(users) can change the format so it can be read/edited in excel, add a column for action.

o/p file to send in email, for example:

output1.out --- email1.abc.com

output2.out --- email2.xyz.com etc....

please let me know how does this works - let me know in detail steps (kind of new to crontab)

Thanks in Advance

If your code works from the command line it will work from cron, for the most part.

So you should get your script working from the command line before "worrying" about cron.

okay, I have issues writing the script in the first place (like I said, new to scripting and crontab etc.. )

so far,

I made a wrapper script:

#!/bin/bash
## command for topdown report genration
for value in {164,174,59,78} ## more business_ids can be added in the future
do
   sh run_script.sh $value 
done

exit 0

this successfully runs and writes the output file in a different location
output164.out
output174.out
etc....

I tried to schedule it every 38 minute, for this I tried in crontab:

 
38 * * * * /complete/path/run_script.sh 2>&1 | tee /complete/output_files_path/* | mail -s "test_report" abc@xyz.com

note: like I mentioned earlier, the output files are many (4 for now), so I used * in the path...

as of now:
I end up with error

mail - blank
spool/mail/user ----- null, hope it's okay

tee: /complete_output_path/output/: ---- is a directory

I need:
All the files in the output directory to be send as attachments to email distribution lists
example: output1.out ----- email1
output2.out ----- email2

please let me know how to make it happen..

First of all, your crontab entry does not schedule every 38 minutes:

38 * * * * /your/crontab/script.sh 

That crontab entry executes at 38 minutes after the hour, every hour.

There are many examples of how to write a crontab entry in the man pages.

For example on linux:

# use /bin/bash to run commands, instead of the default /bin/sh
       SHELL=/bin/bash
       # mail any output to `paul', no matter whose crontab this is
       MAILTO=paul
       #
       # run five minutes after midnight, every day
       5 0 * * *       $HOME/bin/daily.job >> $HOME/tmp/out 2>&1
       # run at 2:15pm on the first of every month -- output mailed to paul
       15 14 1 * *     $HOME/bin/monthly
       # run at 10 pm on weekdays, annoy Joe
       0 22 * * 1-5    mail -s "It's 10pm" joe%Joe,%%Where are your kids?%
       23 0-23/2 * * * echo "run 23 minutes after midn, 2am, 4am ..., everyday"
       5 4 * * sun     echo "run at 5 after 4 every sunday"
       # Run on every second Saturday of the month
       0 4 8-14 * *    test $(date +%u) -eq 6 && echo "2nd Saturday"

Maybe you can review the examples and repost your idea for the correct crontab entry for us to review?

I am not the "kind of guy" to post solutions for people, as I prefer to lead people to learn to think and solve problems for themselves.

Your reply describes a crontab entry that is different than your crontab entry.