LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-14-2018, 11:59 AM   #1
Entropy1024
Member
 
Registered: Dec 2012
Location: UK
Distribution: Ubuntu 16 & 17
Posts: 131

Rep: Reputation: Disabled
Maths with tail


I'm attempting to manage the size of a log file using tail.
I have a string called maxlog which is set to 30 ie
Code:
maxlog=30
Then later in the code after checking if the log file length is over 30 lines I used the following bit of code to remove two of the oldest entries:

Code:
tail -n ${maxlog} - 2 /home/tim/Documents/$HOSTNAME/$HOSTNAME"_"ip.log > /tmp/templog.log && mv /tmp/templog.log /home/tim/Documents/$HOSTNAME/$HOSTNAME"_"ip.log
However it does not work. What is the correct syntax?

Many thanks for any help.
Tim
 
Old 01-14-2018, 12:05 PM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,838

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
Code:
${maxlog} - 2
simply incorrect, this is not the right way to do arithmetics. You need to use:
Code:
$((maxlog - 2))
 
1 members found this post helpful.
Old 01-14-2018, 12:12 PM   #3
Entropy1024
Member
 
Registered: Dec 2012
Location: UK
Distribution: Ubuntu 16 & 17
Posts: 131

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
Code:
${maxlog} - 2
simply incorrect, this is not the right way to do arithmetics. You need to use:
Code:
$((maxlog - 2))
That's great thank you for the correct syntax.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with maths percentages clifford227 General 8 03-17-2011 09:22 PM
tail the output of tail -n 1 raj k yadav Linux - Newbie 5 02-06-2010 11:26 PM
please help me do maths :) darkRoom General 36 04-11-2005 01:03 PM
problem with maths redduck666 General 7 02-12-2005 02:33 PM
And some maths :-P Mathiasdm General 7 11-11-2004 03:48 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:04 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration