Linux send a log (or output from a command) as a mail from the linux console

Sometimes it is nice to send a log or some other file as a email to someone (or a part of a file)

cat myfile.txt | mail -s 'SUBJECT' example@mail.com;

Change myfile.txt, SUBJECT and example@mail.com to something useful.

It is also possible to send the output of a command to someone

ps -ef|mail -s 'SUBJET' example@mail.com;

MySQL execute statements directly from the (linux) console

Executing a query quickly from the console is nice to be able to do (without having to enter the MySQL console).

  • This will simply output the result to the console where you are.
     user@server:~$ mysql -uUSERNAME -p DATABASENAME --execute "REPAIR TABLE position";

    Replace USERNAME and DATABASENAME with your vars

  • If you would like the output to a file
     mysql -uUSERNAME -p DATABASENAME --execute "SELECT * FROM test" > test.sql;

    Replace USERNAME and DATABASENAME with your vars

  • If you would like the output to be sent as a email
     mysql -uUSERNAME -p DATABASENAME --execute "SELECT * FROM test" | mail -s 'SUBJECT' example@mail.com

    Replace USERNAME, DATABASENAME , SUBJECT and example@mail.com with your vars