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
-
hello
put between "MSG="$?(tail -n 20 /var/log/apache2/error.log)" .. echo "$MSG"
-
Does not work, it directly puts the line in text... I'm using it for an email, I want the content of my tail in there as text... it works but it doesn't include line breaks for the log file content, it sends me the content of the log file all at once, which is not very readable... Is there another way, like: command < filename to import ....? Thank you for your valuable help!
-
-
-
Resolved! Find a solution and improve the script with the help of a programmer colleague!
#!/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
-
I modified this line
DATA="Here is the content of the log file:\r\n\r\n""$MSG"
-
if it's the \r that's missing, and like this?
tail -v -n 20 /var/log/apache2/error.log | sed 's/$/\r/' >&3