0

I want to send to my e mail account a mail with log from program execution. This file changes everyday and it's named like this

log-20190703.gz

My attempt:

#!/bin/bash
log_file=logs-$(date +"%Y%m%d").gz
echo "Log file for project" | mailx -s "Log file for start_ux" -a /srv/python/myfold/proj/Log_UX/${log_file}  myemail@gmail.com

that gives me an error:

log_file command not found
Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232

1 Answers1

0

My mailx is using option -a to append a header to the mail. Try option -A to send an attachment.

Edit:

The problem was solved by OP by removing a space character "between variable name and equal sign". Option -a was correct on CentOS and not the problem.

Freddy
  • 25,565
  • it says Account /srv/python/myfold/proj/Log_UX/log-20190703.gz doesn't exist – Marco Fumagalli Mar 07 '19 at 10:18
  • @MarcoFumagalli But the file exists and is readable (zless /srv/python/myfold/proj/Log_UX/log-20190703.gz)? – Freddy Mar 07 '19 at 10:20
  • yes it exists. I can extract it and use cat on it – Marco Fumagalli Mar 07 '19 at 10:23
  • @MarcoFumagalli Hmm. Does (uuencode /srv/python/myfold/proj/Log_UX/${log_file} ${log_file}; echo "Log file for project") | mailx -s "Log file for start_ux" myemail@gmail.com work? – Freddy Mar 07 '19 at 10:31
  • Hmm... What Unix is this and what does the manual for mailx on that Unix say the correct option for attachments is? "Account ... does not exist" sounds odd. On Linux it's usually -A, BSD does not do attachments with mailx, and I'm uncertain for AIX and Solaris. – Kusalananda Mar 07 '19 at 10:34
  • @MarcoFumagalli You said log-20190703.gz is the name of the logfile, but you are using logs-$(date +"%Y%m%d").gz with an additional "s" in the script. – Freddy Mar 07 '19 at 10:37
  • Are you sure you are using curly brackets and not just standard ones? So are you definitely using ${log_file} and not $(log_file) – Raman Sailopal Mar 07 '19 at 10:53
  • Ok solved my issues. I'm on CentOS and i have to use -a instead of -A and also no space between variable name and equal sign – Marco Fumagalli Mar 07 '19 at 10:56