I always endeavour to answer the question, and the actual problem. Seeing your ps actually encouraged me to suggest more awk things.
It may be the complete lack of a newline that causes bc to fail, too. echo will add one on the end, but just piping it in would end up with nothing. Many commands are picky about lines without newlines -- some versions of awk and sed, for instance.
I hope I did not sound ungrateful about the PS, I certainly didn't mean to (I did add a smiley), I just assumed you'd missed it.
Yes it is the lack of a newline causing bc the problem, see my reply to methyl.
---------- Post updated at 06:43 PM ---------- Previous update was at 06:42 PM ----------
Quote:
Originally Posted by vgersh99
how about:
Nope same problem, it's the lack on newline.
---------- Post updated at 06:49 PM ---------- Previous update was at 06:43 PM ----------
Quote:
Originally Posted by methyl
Explanation of the error.
Your "tr" command strips out all line terminators (\n) for some unknown reason and converts them to "+" signs. My version of "sed" will not process lines without a line terminator, but yours appears to work (to my surprise).
The "bc" program fails because the input stream is not terminated with a linefeed character (\n).
When you "echo" the variable $var1 the "echo" statement appends a linefeed character (\n).
Btw. The unix standard version of "tr" will not translate three different characters into one. The length of the translate list must be the same both sides.
In your script this would only matter if there were carriage-return or form-feed characters in the line (which there are clearly not).
The reason why I'm translating the newlines to "+" is to get the "+"s in between the numbers for input into bc.
Yes, you are right the bc works fine once there's a newline appended.
Thanks for the tr info, amended my code.
Fully working and fully understood:
I'll use the more concise awk command next time.
Oracle Linux 6.
Trying to set up a simple monitoring of memory usage. This command does exactly what I want at the command line:
echo $(date +%Y-%m-%d" "%H:%M:%S) $(grep PageTables /proc/meminfo) >> /home/oracle/meminfo.logBut when I put it in my crontab:
* * * * * echo $(date +%Y-%m-%d"... (2 Replies)
Hi,
My command is getting stuck while running it.
observed that the grep command doesn't returned any data ($? was 1) and it failed.
This command is assigned into the variable and used in other command as script progresses. To continue the script output, i have to press ^C twice and script... (2 Replies)
I know that
set line "This is a line."
puts whats between " inside the var line.
But
How do I do the same for
set line "This is a line "with quotations" inside the string." (2 Replies)
OSX 10.9
I am building a script that evaluates the difference between 2 files. Here is a command that does not work transparently.
Running this command in Terminal yields great results; however when I put that line in a .sh script, I get the errors shown below. Am I doing something silly?
... (1 Reply)
Needing a hint. Creating that function called Meter my simple script works well. What I want now is to start the last four commented lines to include or trigger a reaction, if there are more than n lines in that .txt-file it shall display that message for example. But the interpreter says there is... (3 Replies)
I am working with a sh script on a solaris 9 zone (sol 10 host) that grabs information to build the configuration command line. the variables Build64, SSLopt, CONFIGopt, and CC are populated in the script. the script includes
CC=`which gcc`
CONFIGopt=' --prefix=/ --exec-prefix=/usr... (8 Replies)
Hey guys. Hopefully this is an easy one but having reference similar problems on the web I still can't fix it.
I am doing a recursive find and replace from a script. Of course I could just run the damn thing from the command line but it's bugging me now and want to get it working.
grep -rl... (4 Replies)
I am running the following script and passing the following command line arguments :
DBCheckSum_control CA_SITE CA_SITE
Can someone please tell me, why my command line args are not being accepted and assigned to variable "TABLE_NAME'' and "ACTION_TYPE"??
usage()
{
print "Usage: ${0} {... (3 Replies)
Whenever I send an email to my catchall alias via SSH (i.e., locally), Exim successfully pipes the e-mail to a PHP script, as I told it to do. However, when I try to send an e-mail to my catchall alias via my e-mail client (i.e., remotely), Exim won't pipe the e-mail. Any ideas?
My exim.conf... (0 Replies)
Dear forum
I have the following small script:
#!/bin/ksh
echo -e "abba-o" | awk -F '-' '{ print $2 }' | cut -b 1It needs to be ksh.. in bash I don't have this problem.
If I run this on opensuse 10.2 I get this as output: e
If I run this on suse enterprise 10 sp2 then I get this: o
... (1 Reply)