Operating System - HP-UX
1833407 Members
2925 Online
110052 Solutions
New Discussion

what wrong with this script?

 
SOLVED
Go to solution
faust2004
Regular Advisor

what wrong with this script?

Hi, friends
I exec follow script
control=$(cat /tmp/scripts/numero_lineas.log |wc -l)
actual=$(cat /tmp/scripts/numero_lineas.txt)
if [ $control -gt $actual ];then
echo "New lines in logfile"
echo $control > /tmp/scripts/numero_lineas.txt
fi
but error appear:: [3]: test: The specified number is not valid for this command.
how to do with it?

Thanks
Sunny
4 REPLIES 4
Stefan Farrelly
Honored Contributor
Solution

Re: what wrong with this script?


You forgot the |wc -l on the line starting;
actual=
It should look like;
actual=$(cat /tmp/scripts/numero_lineas.txt|wc -l)

Then the test (if ..-gt) will work as its comparing 2 numbers.
Im from Palmerston North, New Zealand, but somehow ended up in London...
Jonathan Baker
Advisor

Re: what wrong with this script?

It depends whats in /tmp/scripts/numero_lineas.txt. My guess is thatyou're trying to compare a number $control with a string $actual which will be the contents of /tmp/scripts/numero_lineas.txt. It may be that you just need to add | wc -l to the command for $actual e.g. actual=$(cat /tmp/scripts/numero_lineas.txt | wc -l)
Stefan Farrelly
Honored Contributor

Re: what wrong with this script?


I can see what youre doing now, the actual line is supposed to equal what is in the file numero_lineas.txt (which should contain 1 line which has a number). However, when you do your first test does this file have any content ? It should contain only 1 line with a number in it, eg. echo 1 > numero_lineas.txt
Im from Palmerston North, New Zealand, but somehow ended up in London...
Yogeeraj_1
Honored Contributor

Re: what wrong with this script?

hello sunny,

i have one script that does something similar.
(see attachment)

Hope it helps

Cheers
Yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)