Notices


Reply
Thread Tools
Posts: 87 | Thanked: 14 times | Joined on Jan 2012
#411
There is an error in this script, it doesn't show nothing when data left <20%. Maybe that's why my modification doesn't work.

Originally Posted by thedead1440 View Post
Edit 2: Warn in red if data left is <20%:
Code:
#!/bin/sh

# Warn in red if data left <20%

tx=$(gconftool -g /cellui/settings/datacounter/transfer/gprs_home_tx_bytes)
rx=$(gconftool -g /cellui/settings/datacounter/transfer/gprs_home_rx_bytes)
total=$(($tx+$rx))
usage=$(gconftool -g /cellui/settings/datacounter/general/gprs_home_notification_period_UI)
amount=`dc $total $usage / p`

if [ $(echo "$amount > 0.800" |bc) -eq 1 ]
then
echo {{red}}"Data left < 20%"
fi
exit 1
bc is required for the above but since harmattan-dev is down; its on my db...
 
Moderator | Posts: 6,214 | Thanked: 6,388 times | Joined on Nov 2011
#412
herno24, i haven't looked at your modification but what i did worked for me, did you install bc and have dc already? If you don't have bc it wont work...
 
Posts: 87 | Thanked: 14 times | Joined on Jan 2012
#413
Originally Posted by thedead1440 View Post
herno24, i haven't looked at your modification but what i did worked for me, did you install bc and have dc already? If you don't have bc it wont work...
I installed only the .deb that you attached.

Edit: I had not installed dc, but now it doesn't show nothing. Before installing dc I could see the MB consumed.

Last edited by herno24; 2013-01-04 at 01:50.
 
Posts: 87 | Thanked: 14 times | Joined on Jan 2012
#414
Ok, i can see 248MB consumed in cyan but it should be displayed in red (because i have a total of 300 MB). Maybe an error in amount or in the IF condition?. This is my modification code:

Code:
#!/bin/sh

# Warn in red if data left <20%

tx=$(gconftool -g /cellui/settings/datacounter/transfer/gprs_home_tx_bytes)
rx=$(gconftool -g /cellui/settings/datacounter/transfer/gprs_home_rx_bytes)
total=$(($tx+$rx))
consumed=$((total/1000000))
usage=$(gconftool -g /cellui/settings/datacounter/general/gprs_home_notification_period_UI)
amount=`dc $total $usage / p`

if [ $(echo "$amount > 0.800" |bc) -eq 1 ]
then
echo "{{red}}$consumed MB"
else
echo "{{cyan}}$consumed MB"
fi
exit 1
 
Moderator | Posts: 6,214 | Thanked: 6,388 times | Joined on Nov 2011
#415
herno24,

My script for what you want:
Code:
#!/bin/sh

# Warn in red if data left <20%

# Data usage in cyan if data left not <20%

tx=$(gconftool -g /cellui/settings/datacounter/transfer/gprs_home_tx_bytes)
rx=$(gconftool -g /cellui/settings/datacounter/transfer/gprs_home_rx_bytes)
total=$(($tx+$rx))
usage=$(gconftool -g /cellui/settings/datacounter/general/gprs_home_notification_period_UI)
totalMB=$((($tx+$rx)/1000000))
amount=`dc $total $usage / p`

if [ $(echo "$amount > 0.800" |bc) -eq 1 ]
then
echo {{red}}"Data left < 20%"
else
echo {{cyan}}"Data used = $totalMB MB"
fi
exit 1
Screenshots:






Edit: I hadn't read thp's post in the previous page; you can remove the {{cyan}} tag and add it to billboard instead so your data usage will be shown in whatever colour you want while the <20% warning will be in red always...

Last edited by thedead1440; 2013-01-04 at 03:26.
 

The Following User Says Thank You to thedead1440 For This Useful Post:
Posts: 87 | Thanked: 14 times | Joined on Jan 2012
#416
Originally Posted by thedead1440 View Post
herno24,

My script for what you want:
Code:
#!/bin/sh

# Warn in red if data left <20%

# Data usage in cyan if data left not <20%

tx=$(gconftool -g /cellui/settings/datacounter/transfer/gprs_home_tx_bytes)
rx=$(gconftool -g /cellui/settings/datacounter/transfer/gprs_home_rx_bytes)
total=$(($tx+$rx))
usage=$(gconftool -g /cellui/settings/datacounter/general/gprs_home_notification_period_UI)
totalMB=$((($tx+$rx)/1000000))
amount=`dc $total $usage / p`

if [ $(echo "$amount > 0.800" |bc) -eq 1 ]
then
echo {{red}}"Data left < 20%"
else
echo {{cyan}}"Data used = $totalMB MB"
fi
exit 1
I don't know why, but it doesn't work. I installed bc from your attachment and dc via terminal (apt-get install dc), is that correct?.
 
Moderator | Posts: 6,214 | Thanked: 6,388 times | Joined on Nov 2011
#417
Originally Posted by herno24 View Post
I don't know why, but it doesn't work. I installed bc from your attachment and dc via terminal (apt-get install dc), is that correct?.
Yes...

10chars

P.S. did you chmod 775 your sh file and is it in /home/user/ ?


Edit 2: Do a sh /path/to/script as user in terminal to see if the output satisfies what you want before putting it into Billboard...

Last edited by thedead1440; 2013-01-04 at 03:13.
 
Posts: 87 | Thanked: 14 times | Joined on Jan 2012
#418
Originally Posted by thedead1440 View Post
Edit 2: Do a sh /path/to/script as user in terminal to see if the output satisfies what you want before putting it into Billboard...
This is the result:
Code:
#!/bin/sh: not found
dc: Could not open file 242418745
dc: Could not open file 1000000000
dc: Will not attempt to process directory /
dc: Could not open file p
(standard_in) 1: syntax error
sh: 1: unknown operand
{{cyan}}Data used = 242 MB
 
Moderator | Posts: 6,214 | Thanked: 6,388 times | Joined on Nov 2011
#419
Can you do a dc of those values manually in terminal not via sh script? Also why would it say #!/bin/sh not found? Is your text editor putting it correct? Why not just use vi(m) or nano on the phone via ssh otherwise to rule out your text editor...
 
Posts: 87 | Thanked: 14 times | Joined on Jan 2012
#420
Originally Posted by thedead1440 View Post
Can you do a dc of those values manually in terminal not via sh script?
Like this?:
Code:
~ $ usage=$(gconftool -g /cellui/settings/datac
ounter/general/gprs_home_notification_period_UI)
~ $ totalMB=$((($tx+$rx)/1000000))
-/bin/sh: arithmetic syntax error
~ $ `dc $total $usage / p`
dc: Could not open file 1000000000
dc: Will not attempt to process directory /
dc: Could not open file p
 
Reply

Thread Tools

 
Forum Jump


All times are GMT. The time now is 22:12.