|
2013-01-27
, 11:59
|
Moderator |
Posts: 6,215 |
Thanked: 6,400 times |
Joined on Nov 2011
|
#562
|
|
2013-01-27
, 14:29
|
Moderator |
Posts: 6,215 |
Thanked: 6,400 times |
Joined on Nov 2011
|
#563
|
True, works without -n too.
Also I'm using this script to show uptime in decimal numbers:
Now I want it to show the after decimal point only when upime is <10 days.Code:#!/usr/bin/python # Show Device Uptime in decimal days sc = u"\u2622" seconds = int(float(open('/proc/uptime').read().split()[0])) print 'up: '+("%.1f" % (float(seconds)/float(60*60*24))).replace('.', ',')+' d'+' '+sc.encode('utf-8')
So that it would print "9,9 days" and "10 days".
Could someone put that rule to the script please?
#!/bin/sh #uptime days=$(cat /proc/uptime | awk '{print $1}') days2=`dc $days 86400 / p | cut -c1-4` days3=`dc $days 86400 / p | awk -F"." '{print $1}'` if [ $days3 -lt 10 ] then echo -n -e up\: $days2 else echo -n -e up\: $days3 fi echo -n -e \ "\xe2\x98\xA2"
The Following User Says Thank You to thedead1440 For This Useful Post: | ||
|
2013-01-27
, 15:11
|
|
Posts: 141 |
Thanked: 267 times |
Joined on May 2010
@ Germany
|
#564
|
#!/usr/bin/python # Show Device Uptime in decimal days sc = u"\u2622" seconds = int(float(open('/proc/uptime').read().split()[0])) days = float(seconds)/float(60*60*24) days = "{0:.0f}".format(days) if seconds >= 864000 else "{0:.1f}".format(days) output = " ".join(['up:',days.replace('.', ','),'d',sc.encode('utf-8')]) print output
The Following 2 Users Say Thank You to EmaNymton For This Useful Post: | ||
|
2013-01-27
, 15:22
|
Moderator |
Posts: 6,215 |
Thanked: 6,400 times |
Joined on Nov 2011
|
#565
|
Traceback (most recent call last): File "/home/user/uptime2.py", line 7, in <module> days = "{:.0f}".format(days) if seconds >= 86400 else "{:.1f}".format(days) ValueError: zero length field name in format
|
2013-01-27
, 15:29
|
|
Posts: 141 |
Thanked: 267 times |
Joined on May 2010
@ Germany
|
#566
|
The Following 2 Users Say Thank You to EmaNymton For This Useful Post: | ||
|
2013-01-27
, 15:46
|
|
Community Council |
Posts: 664 |
Thanked: 1,648 times |
Joined on Apr 2012
@ Hamburg
|
#567
|
It requires dc to work but IIRC dc is by default present...Code:#!/bin/sh #uptime days=$(cat /proc/uptime | awk '{print $1}') days2=`dc $days 86400 / p | cut -c1-4` days3=`dc $days 86400 / p | awk -F"." '{print $1}'` if [ $days3 -lt 10 ] then echo -n -e up\: $days2 else echo -n -e up\: $days3 fi echo -n -e "\xe2\x98\xA2"
|
2013-01-27
, 15:50
|
Moderator |
Posts: 6,215 |
Thanked: 6,400 times |
Joined on Nov 2011
|
#568
|
|
2013-01-27
, 16:04
|
|
Community Council |
Posts: 664 |
Thanked: 1,648 times |
Joined on Apr 2012
@ Hamburg
|
#569
|
RM696-21-3_PR_001:~# dpkg -l | grep dc ii libstdc++6 4.4.1-0maemo14+0m6 The GNU Standard C++ Library v3
|
2013-01-27
, 16:06
|
Moderator |
Posts: 6,215 |
Thanked: 6,400 times |
Joined on Nov 2011
|
#570
|
Telegram | Openrepos | GitHub | Revolut donations