Jump to content
jeffreywhunter

Simple Script Help [SOLVED]

7 posts in this topic Last Reply

Recommended Posts

Posted (edited)

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

Share this post


Link to post

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

Share this post


Link to post
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...

Share this post


Link to post

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.

Share this post


Link to post
55 minutes ago, bonienl said:

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

 

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

Share this post


Link to post
Posted (edited)
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

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now