Sponsored Content
Top Forums Shell Programming and Scripting Bash Script Issues (If statement for file copying) Post 302664787 by The_Ardly374 on Saturday 30th of June 2012 05:09:34 PM
Old 06-30-2012
Bash Script Issues (If statement for file copying)

Writing a bash script for use with Geektool, pulls the battery info, and shuffles images around so that an Image geeklet can display the correct expression as the desktop background. (Eventually I intend to make it more intricate, based on more variables, and add more expressions)

I'm extremely new to the language, but the script below did return a result the first time I ran it through Geektool. The only problem is that the variable did not match the result (batt at 95%, result was for 5% and below). It stopped working after that.

The percentage display works every time, but that's most likely because I didn't write that part of the script, I scavenged it. I'd rather use a variable than rerun the calculation over and over, but I couldn't get it to work.






Code:
#!/bin/bash

asbreg=`ioreg -rc "AppleSmartBattery"`

maxcap=`echo "${asbreg}" | awk '/MaxCapacity/{print $3}'`;
curcap=`echo "${asbreg}" | awk '/CurrentCapacity/{print $3}'`;

prcnt=`echo "scale=2; 100*$curcap/$maxcap" | bc`;

if [ 100*$curcap/$maxcap -gt 15 ] ; then

cp /Users/User/Desktop/Faces/Happy.png /Users/User/Desktop/Faces/Current/Current.png

elif [ 100*$curcap/$maxcap -gt 10 ] ; then

	cp /Users/User/Desktop/Faces/Queasy.png /Users/User/Desktop/Faces/	Current/Current.png

	elif [ 100*$curcap/$maxcap -gt 5 ] ; then

		cp /Users/User/Desktop/Faces/Angry.png /Users/User/Desktop/Faces/Current/Current.png

		elif [ 100*$curcap/$maxcap -gt 1 ] ; then 

			cp /Users/User/Desktop/Faces/Unconcious.png /Users/User/Desktop/Faces/Current/Current.png

fi

printf "%1.0f%%" ${prcnt};


#EOF

 

10 More Discussions You Might Find Interesting

1. Solaris

Issues with copying using rsh

Hi, I'm having a few issues with rsh. I'm trying to copy data from one host to another using tar with the following command: tar -cf - /data | rsh xx.xx.xx.xx tar -xf - I'm copying the data from an X4100 to an X4140 server and have done this before with no issues. But with these... (1 Reply)
Discussion started by: Chains
1 Replies

2. UNIX for Dummies Questions & Answers

IP connection Bash script issues

Hello I need assistance with a bash script that needs to tell me whether in the last "x" days (which is a variable) anyone connected to the xxxx IP (which is another variable). Thank you! (1 Reply)
Discussion started by: Melchiah
1 Replies

3. Shell Programming and Scripting

Bash script issues

Hi. The below part of my bash script kicks out the following error message: $ ./extract_eod_report_stats_new.sh 2010-04-23 ./extract_eod_report_stats_new.sh: line 204: syntax error near unexpected token `(' ./extract_eod_report_stats_new.sh: line 204: `TRANSACTIONS_RECEIVED_TOP=`grep... (6 Replies)
Discussion started by: Peter.Lovell
6 Replies

4. Shell Programming and Scripting

Noob's 1st...bash-script for copying one file into many

I have one file "file.a.b.c-d.r" that I would like to use to spawn 4 other files: "file.a.b.1-A.r" "file.a.b.1-B.r" "file.a.b.1-C.r" "file.a.b.1-D.r" where the field "c-d" changes into my 1 and A-D. I was doing this manually at the prompt with > cp "file.a.b.c-d.r" "file.a.b.1-A.r" >... (13 Replies)
Discussion started by: WSUToad
13 Replies

5. Shell Programming and Scripting

Bash Script issues

So what i am trying to do is write a script that takes in any number of scrambeled words and unscrambles them. I have already addressed the issues of partial matches, exits silently if there are no matches, and finds words regardless of case that they were input. but while trying to get it so... (3 Replies)
Discussion started by: alindner
3 Replies

6. Shell Programming and Scripting

Bash: renaming file issues.

Hi, i want to rename a group of directories and files of my music, some items are like this: - , for directories. - , for files. I want to do something like this: , for directories. , for files. This is my code: #!/bin/bash for fname in *.mp3; do echo item: $fname mv... (2 Replies)
Discussion started by: josco1982
2 Replies

7. Shell Programming and Scripting

Unix bash script (mv issues);

Hey guys, I've registered here as I need urgent help. This is assignment for school and as you can see below I've completed the work. I'm simply stuck on one area. :wall: This script takes the first parameter (which is to be the new extension) and each parameter after that is a file... (1 Reply)
Discussion started by: Cynosure
1 Replies

8. Shell Programming and Scripting

Copying large files in a bash script stops execution

Hello, I'm new to this forum and like to first of all say hello to everyone. I've got a really annoying problem at the moment. I'm trying to rsync some files (about 200MB with one file of 120MB) from a Raspberry PI with raspbian to a debian server via rsync. This procedure is stored in a... (3 Replies)
Discussion started by: wex_storm
3 Replies

9. Shell Programming and Scripting

Need help in finding and copying list of files using bash shell script

Dear All, I have a situation where I want to copy some files of type .txt. These files are o/p from one program. Some of the files are named as fileName .txt instead of fileName.txt after fileName by mistake I have specified "space". Now I want to move these files as follows. mv fileName*... (13 Replies)
Discussion started by: linuxUser_
13 Replies

10. UNIX for Beginners Questions & Answers

Bash to append array value to file before copying

The bash stores each uniqueid in an array and then passes them to %q to get the unique path. That seems to work what I am having trouble with is renaming each .png with the unique value in %q. I thought it was working but upon closer inspection, a .png file is being sent to scp.... but only 1 and... (21 Replies)
Discussion started by: cmccabe
21 Replies
XBATTBAR(1)						    BSD General Commands Manual 					       XBATTBAR(1)

NAME
xbattbar -- show battery status in X Window SYNOPSIS
xbattbar [-a] [-t thickness] [-p interval] [-I color] [-O color] [-i color] [-o color] [-c] [-s script-name] [top | bottom | left | right] DESCRIPTION
xbattbar shows the current (laptop) battery status in the X window environment. Battery status is obtained through the APM kernel module. The APM kernel module depends on your UNIX platform, therefore, consult your documentation for its detail. xbattbar shows its battery status in a simple bar indicator. -a option makes the indicator window keep always on top of your screen. The thickness of the indicator is 3 pixels in default and you can set the thickness as a parameter of -t option. This indicator is appeared in the bottom of the display, as its default. The option top, left, or right forces the status indicator to be at the top, left, and right of the display, respectively. Though it's a default, you can also use buttom as the option. In the case the AC line is on-line (plugged in), its color of the bar indicator consists of "green" and "olive drab" portions. The "green" portion shows its battery charging level. These colors can be changed by -I and -O options. In the other case (AC line is off-line), the "blue" portion of the bar indicator shows the percentage of its remaining battery level. The color conbination for the AC off-line case can be changed by -i and -o options. xbattbar trys to know its battery status in every 10 seconds in default. This is achived by APM polling. If it is used with option -c then ACPI polling will be used. You can use your external script for check battery status. It must print two lines to STDOUT 'battery=value' and 'ac_line=on|off -p option sets the polling interval in second. If the mouse cursor enters in the status indicator, the diagnosis window appears in the center of the display, which shows both AC line sta- tus and battery remaining level. This diagnosis window disappears if the mouse cursor leaves from the status indicator. AUTHOR
Suguru Yamaguchi <suguru@wide.ad.jp>, Akira Kato <kato@wide.ad.jp>, Noriyuki Shigechika <nazo@wide.ad.jp>, Dmitry E. Oboukhov <unera@debian.org> BSD
December 5, 1998 BSD
All times are GMT -4. The time now is 04:41 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy