Simple Script Help [SOLVED]


Recommended Posts

I'm trying to build a log file to trace my memory and see if I can track a trend where my server crashes after a couple of days.  Its been mentioned to use "free -h" to create a simple track.  I've used User Scripts (nice tool!) to create a cron job which works, but I'm trying to get the output readable in Windows Notepad.  Pretty sure I'm dealing with an ASCII character issue for CRLF, but not been able to find an answer online (they want to use echo -e or $ or /n, which has not worked).  Since almost all of our operating software today is a descendant of Unix, Mac, or MS operating SW, we are stuck with the line ending confusion - I just don't know the solution for DOS to read Linux!

 

#!/bin/bash
echo '======Start=======' >> /boot/log_free_memory.log
date >> /boot/log_free_memory.log
free -h >> /boot/log_free_memory.log
echo '======End=======' >> /boot/log_free_memory.log

The output I get does not match what I want when viewing the file in windows. 

 

However, it displays perfectly when I paste it into the code box and insert here (also displays fine if you cat the file):

 

======Start=======
Mon May 14 14:31:04 CDT 2018
              total        used        free      shared  buff/cache   available
Mem:            15G        3.5G        1.4G        520M         10G         10G
Swap:            0B          0B          0B
======End=======

And Programmers Notepad displays it correctly.

 

So I'm missing the magic.  How do I get windows editor to view the file correctly.  I suppose I could just use Programmers Notepad to view log files...  Suddenly dawned on me that editing config files with notepad is probably a no-no?!?  ?

Edited by jeffreywhunter
Link to comment

The easiest would be to use a true editor, like notepad++ which understands all formats.

 

If you insist in standard notepad and MS format, change your script like this:

#!/bin/bash
echo '======Start=======' | todos >> /boot/log_free_memory.log
date | todos >> /boot/log_free_memory.log
free -h | todos >> /boot/log_free_memory.log
echo '======End=======' | todos >> /boot/log_free_memory.log

 

  • Upvote 1
Link to comment
23 minutes ago, bonienl said:

The easiest would be to use a true editor, like notepad++ which understands all formats.

 

If you insist in standard notepad and MS format, change your script like this:


#!/bin/bash
echo '======Start=======' | todos >> /boot/log_free_memory.log
date | todos >> /boot/log_free_memory.log
free -h | todos >> /boot/log_free_memory.log
echo '======End=======' | todos >> /boot/log_free_memory.log

 

Thanks!  I think I'll go with the easiest (and most consistent for the rest of the world!).  I have programmers notepad which also works/reads the files perfectly...

Link to comment

It's rather interesting that notepad after all these years hasn't learned that if it uses the C runtime library and opens the file in text mode, then the runtime library will normalize both Unix and Windows line breaks into just a '\n' character - so it will only be mac-specific files that will have issues since they have reversed order of carriage return and line feed.

Link to comment
1 hour ago, bonienl said:

Microsoft is excited they (finally) fixed the issue :)

See https://blogs.msdn.microsoft.com/commandline/2018/05/08/extended-eol-in-notepad/

 

 

20 minutes ago, pwm said:

 

Has someone really, really, important at Microsoft just died? Or how did they manage this ultimate feat of glorious high-tech coding?

 

I like the fact Notepad broke Linux files, it kept things exclusive..... :)

Edited by CHBMB
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.