LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 01-13-2016, 06:05 PM   #16
Fixit7
Senior Member
 
Registered: Mar 2014
Location: El Lago, Texas
Distribution: Ubuntu_Mate 16.04
Posts: 1,374

Original Poster
Rep: Reputation: 169Reputation: 169

One more $.

I want to print the design capacity of the battery.

This is not working.

Quote:
grep design /proc/acpi/battery/*/capacity >> Battery_State.txt
Attached Thumbnails
Click image for larger version

Name:	Batt_Message.png
Views:	18
Size:	44.1 KB
ID:	20521  

Last edited by Fixit7; 01-13-2016 at 06:16 PM.
 
Old 01-13-2016, 06:55 PM   #17
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
"Not working" is not helpful.

Whenever you ask a question, you should answer three things:

1) What are you doing/running. In this case you covered that with:
Code:
grep design /proc/acpi/battery/*/capacity >> Battery_State.txt
2) What is the expected output. You also answered that (sort of):
Code:
design capacity: 7800 mAh
3) What is the actual output. This is the part you keep missing.



In other words, what is the command/script/program doing that you do not want, and/or what is the command/script/program not doing that you do want. Is the command outputting the wrong thing? Anything? Error messages?

Often the solution comes from simply asking one more question, why? Why am I running what I'm running? Why do I expect that output? And most importantly, why is it giving me the result that it is? I can't even count the number of times I've run into some wacky problem, started typing up a thread on LQ, and as I'm answering those questions, I find the solution myself before I even hit Submit.

Last edited by suicidaleggroll; 01-13-2016 at 07:12 PM.
 
Old 01-13-2016, 07:49 PM   #18
Fixit7
Senior Member
 
Registered: Mar 2014
Location: El Lago, Texas
Distribution: Ubuntu_Mate 16.04
Posts: 1,374

Original Poster
Rep: Reputation: 169Reputation: 169
Output of script.
Quote:
01/13/16 07:47:37 PM
/proc/acpi/battery/BAT0/state:remaining capacity: 5387 mAh
/proc/acpi/battery/BAT0/info:last full capacity: 5667 mAh
/proc/acpi/battery/BAT0/state:charging state: charging
I do my best, but I am not perfect.

We all makes mistakes.

Is there a way for my script to output the file name of the script that I invoked to that same file?

For ex:

Invoked by test.sh
01/13/16 07:47:37 PM
/proc/acpi/battery/BAT0/state:remaining capacity: 5387 mAh

Last edited by Fixit7; 01-13-2016 at 07:51 PM.
 
Old 01-15-2016, 09:04 AM   #19
Fixit7
Senior Member
 
Registered: Mar 2014
Location: El Lago, Texas
Distribution: Ubuntu_Mate 16.04
Posts: 1,374

Original Poster
Rep: Reputation: 169Reputation: 169
Quote:
Originally Posted by Fixit7 View Post
Output of script.

Is there a way for my script to output the file name of the script that I invoked to that same file?
# $0 shows the script that has been invoked
# echo $0 >> date.txt
 
Old 01-15-2016, 09:11 AM   #20
Fixit7
Senior Member
 
Registered: Mar 2014
Location: El Lago, Texas
Distribution: Ubuntu_Mate 16.04
Posts: 1,374

Original Poster
Rep: Reputation: 169Reputation: 169
I am using Tahr Pup 6.0.5.

I can not figure out why this line 'grep design /proc/acpi/battery/*/capacity >> Battery_State.txt '
does not send the design capacity to the text file.

Can someone help me ?

Quote:
#!/bin/bash
#
# Linux Puppy 6.3.0
#
# Send battery status to file every 5 minutes 10 times
#
count=1
done=0

while [ $count -le 10 ]
do
(( count++ ))

date "+ m/d/%y %r" >> Battery_State.txt

grep remaining /proc/acpi/battery/*/state >> Battery_State.txt
grep full /proc/acpi/battery/*/info >> Battery_State.txt
grep charging /proc/acpi/battery/*/state >> Battery_State.txt
# next line does not work ??
grep design /proc/acpi/battery/*/capacity >> Battery_State.txt
sleep 300 # Update file every 5 minutes
done
 
Old 01-15-2016, 10:05 AM   #21
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
See my earlier post on this question. You need to tell us what it DOES do, not just that it doesn't work. Have you actually looked inside /proc/acpi/battery/*/capacity to see if there are any lines that contain the word "design"?
 
Old 01-15-2016, 10:17 AM   #22
Fixit7
Senior Member
 
Registered: Mar 2014
Location: El Lago, Texas
Distribution: Ubuntu_Mate 16.04
Posts: 1,374

Original Poster
Rep: Reputation: 169Reputation: 169
Quote:
Originally Posted by suicidaleggroll View Post
See my earlier post on this question. You need to tell us what it DOES do, not just that it doesn't work. Have you actually looked inside /proc/acpi/battery/*/capacity to see if there are any lines that contain the word "design"?
This is the file it produces.
Quote:
01/15/16 09:33:43 AM
/proc/acpi/battery/BAT0/state:remaining capacity: 5707 mAh
/proc/acpi/battery/BAT0/info:last full capacity: 5741 mAh
/proc/acpi/battery/BAT0/state:charging state: charged
My previous post with the screenshot shows what shows on my screen when I click on the battery icon.

The proc statements were found on the internet and I do not understand how they work.

I can only post what I know and not what I do not understand.

Have you used my script and seen what it does ?

Last edited by Fixit7; 01-15-2016 at 10:18 AM.
 
Old 01-15-2016, 12:13 PM   #23
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
grep is a text searching tool. It searches the file you tell it for the word you tell it, and prints out any lines that match.

Code:
grep design /proc/acpi/battery/*/capacity
will search for the word "design" in a file called "capacity" that's located in /proc/acpi/battery/*/ (the * matches any directory in that location).

Your system either doesn't have a file called capacity in that location, or that file does not contain the word "design". If you want to fix it, you'll need to see what is actually in that file so you can search for the right phrase.

I can't run your script as none of my systems have a /proc/acpi/battery directory. Entries in /proc/acpi are VERY system and distribution-specific, nobody here will be able to test your script unless they just happen to be running the exact same Linux distribution as you on the exact same hardware.
 
Old 01-15-2016, 12:48 PM   #24
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,793

Rep: Reputation: 5952Reputation: 5952Reputation: 5952Reputation: 5952Reputation: 5952Reputation: 5952Reputation: 5952Reputation: 5952Reputation: 5952Reputation: 5952Reputation: 5952
Looks like a syntax error.

Code:
grep design /proc/acpi/battery/*/capacity >> Battery_State.txt
Should be

Code:
grep design /proc/acpi/battery/*/info >> Battery_State.txt
 
Old 01-15-2016, 01:41 PM   #25
Fixit7
Senior Member
 
Registered: Mar 2014
Location: El Lago, Texas
Distribution: Ubuntu_Mate 16.04
Posts: 1,374

Original Poster
Rep: Reputation: 169Reputation: 169
Thanks Michaelk.

I misinterpretated info as being a word it was searching for instead of a directory name.

Before you posted, I was up to this.

It's not perfect, but it suits my needs. :-)

Quote:
#!/bin/bash
#
# Linux Puppy 6.3.0
#
# Send battery status to file every 5 minutes 10 times
#

count=1
done=0

while [ $count -le 10 ]
do
(( count++ ))

date "+ m/%d/%y %r" >> Battery_State.txt

grep remaining /proc/acpi/battery/*/state >> Battery_State.txt
grep full /proc/acpi/battery/*/info >> Battery_State.txt
grep charging /proc/acpi/battery/*/state >> Battery_State.txt
grep "design capacity" /proc/acpi/battery/BAT0/info >> Battery_State.txt

sleep 300 # Update file every 5 minutes
done
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Difficulty getting association Haines Linux - Networking 9 03-26-2015 01:57 PM
difficulty enios LinuxQuestions.org Member Intro 5 08-30-2011 11:50 PM
Difficulty in understanding Gins Programming 6 07-12-2006 04:22 PM
Difficulty in Cinelerra BobNutfield Linux - Software 2 02-15-2006 07:33 AM
difficulty with wireless - sometimes 105659 Linux - Wireless Networking 0 01-22-2006 08:36 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 08:36 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