We help IT Professionals succeed at work.

production of and scheduling sun unix - solaris -  job to move a csv file to a user via email

at the moment cron runs a weekly job which interrogates a db and produces a set of csv files which reside in a folder on the same sun server.

I need to work out the easiest way to set up a job which will transfer these files to an email address preferably.
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2007
Commented:
You may send them to an email by running a crontab job at required time which will send them one by one.

#!/usr/bin/ksh
cd /to/my/dir
for file in *.csv
do
    /usr/bin/cat $file | /usr/bin/mailx -s "text subject" user@domain.com >> /to/my/log/script.log 2>>&1
done
Greetings,

If I understand correctly you wish to convert the cron results into an email and which is then sent to the user.

By default cron jobs sends a email to the user account executing the cronjob. If this is not working you can place the following command at the top of the crontab file,

MAILTO=emaiid@domain.com

try it and let me know if it works for you.

Regards,
Casemanager
CERTIFIED EXPERT
Top Expert 2007

Commented:
Hi casemanager,

Sun Solaris crontab does not support MAILTO env. variable.

Do you need to preserve the files as attachments or is it sufficient to have the file content in the email message body, one message per csv file?
if yes, comment #1 would be your accepted answer.
Paul VincentIT support

Author

Commented:
apologies for not getting back sooner - I am on dialysis and am not always up to working. omarfarid's solution works just as I want it to. Thanks casemanager for looking as well, and bummerlord for reinforcing the solution.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.