Carriage return
Solved
enyrix
Posted messages
167
Status
Member
-
dubcek Posted messages 18627 Registration date Status Contributor Last intervention -
dubcek Posted messages 18627 Registration date Status Contributor Last intervention -
Hello,
I am programming an email that will contain the return of a command executed on a server. I am storing the return of my command in a variable, but I would like to preserve the carriage returns contained in my log file... How can I do that?
I am programming an email that will contain the return of a command executed on a server. I am storing the return of my command in a variable, but I would like to preserve the carriage returns contained in my log file... How can I do that?
MSG=$?(tail -n 20 /var/log/apache2/error.log) DATA="Here is the content of the log file:\r\n\r\n$MSG"
6 answers
Resolved! Find a solution and improve the script with the help of a programmer colleague!
Thank you for your help! Just so you know, unix2dos is now tofrodos for Ubuntu...
#!/bin/bash SUBJECT="Server Notification" MAILSERVER="relais.xxxx.xx" PORT="25" MAILFROM="xxxx@xxxx" MAILTO="xxxx@xxxx" #### SEND MAIL via RAW TCP ####### echo echo "Connecting to $MAILSERVER on Port $PORT"; echo "Please wait ... " echo exec 3<>/dev/tcp/$MAILSERVER/$PORT if [ $? -ne 0 ] ; then echo echo "ERROR: Cannot connect to the Mail Server"; echo "Please check the servername and/or the port number" exit else echo -en "HELO mail.email.com\r\n" >&3 echo -en "MAIL FROM:$MAILFROM\r\n" >&3 echo -en "RCPT TO:$MAILTO\r\n" >&3 echo -en "DATA\r\n" >&3 echo -en "Subject: $SUBJECT\r\n\r\n" >&3 echo -en "Here is the content of the log file:\r\n\r\n" >&3 tail -v -n 20 /var/log/apache2/error.log | while read line do echo -en "$line\r\n" >&3 done echo -en ".\r\n" >&3 echo -en "QUIT\r\n" >&3 cat <&3 echo echo echo "Mail sent!" echo fi
Thank you for your help! Just so you know, unix2dos is now tofrodos for Ubuntu...
avec des " ça fonctionne, montre ton code
$ tail a2 aaa aaa bbb b b b ccc ccc $ MSG="$(tail a2)" $ echo $MSG aaa aaa bbb b b b ccc ccc $ echo "$MSG" aaa aaa bbb b b b ccc ccc $ $ DATA="Voici le contenu du fichier log:\r\n\r\n""$MSG" $ echo -e "$DATA" Voici le contenu du fichier log: aaa aaa bbb b b b ccc ccc $
Voici le contenu du fichier log:
#!/bin/bash MSG="$(tail -n 20 /var/log/apache2/error.log)" DATA= echo "Here is the log file content:\r\n\r\n$MSG" SUBJECT="Server Notification" MAILSERVER="XXXXXXXX" PORT="25" MAILFROM="XXXXXXXXX" MAILTO="XXXXXXXXXXX" #### SEND MAIL via RAW TCP ####### echo echo "Connecting to $MAILSERVER on Port $PORT"; echo "Please wait ... " echo exec 3<>/dev/tcp/$MAILSERVER/$PORT if [ $? -ne 0 ] ; then echo echo "ERROR: Cannot connect to the Mail Server"; echo "Please check the servername and/or the port number" exit fi echo -en "HELO mail.email.com\r\n" >&3 echo -en "MAIL FROM:$MAILFROM\r\n" >&3 echo -en "RCPT TO:$MAILTO\r\n" >&3 echo -en "DATA\r\n" >&3 echo -en "Subject: $SUBJECT\r\n\r\n" >&3 echo -en "$DATA\r\n" >&3 echo -en ".\r\n" >&3 echo -en "QUIT\r\n" >&3 cat<&3 echo echo echo "Mail sended!" echo
Try the unix2dos command, which, if it's not installed by default, should be in the official packages.