x
This website is using cookies. We use cookies to ensure that we give you the best experience on our website. More info. That's Fine
HPC:Factor Logo 
 
Latest Forum Activity

Linux Users: Carriage Returns in a Script?

Jake Page Icon Posted 2023-06-12 5:11 PM
#
Avatar image of Jake
Moderator
H/PC Vanguard

Posts:
2,831
Location:
Choking on the stench of ambition in Washington DC
Status:
I'm running a successful script with the PinePhone Beta/Manjaro Phosh/gxmessage (notify-send doesn't seem to work with Phosh). The script itself is fine:

batt1="$(cat /sys/class/power_supply/ip5xxx-battery/capacity)" batt2="$(cat /sys/class/power_supply/axp20x-battery/capacity)" batt3="= $(($batt1 + $batt2))%" uptime="$(sudo tuptime | awk -F'=' '/System uptime:/ {print substr($2, 1, length($2)-3)}')" weather="$(curl -s http://rss.accuweather.com/rss/liveweather_rss.asp\?metric\=${METRIC}\&locCode\=20902 \ | sed -n '/Currently:/ s/.*: \(.*\): \([0-9]*\)\([CF]\).*/\2°\3 \1/p')" s="battery: $batt1% + $batt2% $batt3 uptime: $uptime weather: $weather" gxmessage $s


Resulting in:

battery: 100% + 95% = 195% uptime: 21h 1m weather: 74° Cloudy


But these outputs are crowded onto one line. In gxmessage/bash, is there a way to insert two carriage returns between each command?

My fingers bleed from googling but I can't find the solution.

Jake
 Top of the page
C:Amie Page Icon Posted 2023-06-12 5:41 PM
#
Avatar image of C:Amie
Administrator
H/PC Oracle

Posts:
18,001
Location:
United Kingdom
Status:
echo '\n\n'
printf "\n\n"

Echo can be a bit variable so try the later. Do \r\n\r\n for Windows.
 Top of the page
Jake Page Icon Posted 2023-06-12 7:50 PM
#
Avatar image of Jake
Moderator
H/PC Vanguard

Posts:
2,831
Location:
Choking on the stench of ambition in Washington DC
Status:
Thanks, Chris, for the speedy, helpful directions. I ended up with this:

s="battery: $batt1% + $batt2% $batt3\n\nuptime: $uptime\n\nweather: $weather" echo -e $s | gxmessage -file -


Which produced the desired spacing.

I'm so amazed how people have mastered this syntax--I can barely type it correctly, let alone figure it out by myself.

Jake
 Top of the page
stingraze Page Icon Posted 2023-06-14 3:25 PM
#
Avatar image of stingraze
Subscribers
H/PC Vanguard

Posts:
3,685
Location:
Japan
Status:
That looks like a cool script to have. I want to try it on my Pinephone.
 Top of the page
Jake Page Icon Posted 2023-06-14 3:54 PM
#
Avatar image of Jake
Moderator
H/PC Vanguard

Posts:
2,831
Location:
Choking on the stench of ambition in Washington DC
Status:
@stingraze -- ah, I didn't know you had a pinephone! For the weather, I'm not sure how to insert a Japanese location in place of the US zipcode:

http://rss.accuweather.com/rss/liveweather_rss.asp/?metric\=${METRIC}\&locCode\=20902


but the rest should work as long as you have gxmessage installed along tuptime (which needs sudo, so you might have to give yourself God privileges in
/etc/sudoers


tuptime is wondrous since it remembers your last uptime and starts there on reboot (eg: your uptime is 59min; when you resart, uptime begins at 59min). You can begin anew by blowing away tuptime's cache in
/var/lib/tuptime/tuptime.db


I've got a wifi toggle script and couple of others, should they be in your interest. (I've also got the right tuptime version for Phosh which I can send for manual install).

The need for the battery percentage is that the original upowerd doesn't work and my recompile of upowerd doesn't work anymore in Manjaro Phosh Beta ver 33. I don't know why, and I don't think another recompile will change things. The joys of rough software...

Jake
 Top of the page
stingraze Page Icon Posted 2023-06-15 4:14 AM
#
Avatar image of stingraze
Subscribers
H/PC Vanguard

Posts:
3,685
Location:
Japan
Status:
@Jake

Thank you for additional information of the script.
I will let you know when I put it on my Pinephone. I need to update the OS first though.

-stingraze

Edited by stingraze 2023-06-15 4:14 AM
 Top of the page
stingraze Page Icon Posted 2023-07-22 11:25 AM
#
Avatar image of stingraze
Subscribers
H/PC Vanguard

Posts:
3,685
Location:
Japan
Status:
So, after upgrading to a newer OS, I finally had the time to fiddle around with the shell script.

I wrote a very short one based on Jake's, but I couldn't install gxmessage yet so I just made it print out to the command line.
I will try to see if curl is installed on my system and if I can connect it to the weather API.

Edited by stingraze 2023-07-22 11:26 AM




(pinephone-kbd-battery.jpg)



Attachments
----------------
Attachments pinephone-kbd-battery.jpg (88KB - 0 downloads)
 Top of the page
Jake Page Icon Posted 2023-07-22 6:10 PM
#
Avatar image of Jake
Moderator
H/PC Vanguard

Posts:
2,831
Location:
Choking on the stench of ambition in Washington DC
Status:
@stingraze -- which OS are you running? On Manjaro Phosh, notify-send didn't work but gxmessage did; I never figured out why.

My current flavor is Manjaro Phosh with xfce desktop. xfce's plugins preclude hassle of above script/gxmessage-install since their weather and genmon plugins do it all. If you do switch, post back and I can give you the genmon scripts for accurate battery level and tuptime output.

xfce, being a desktop, is not finger-friendly, so you depend mostly on kb shortcuts. I also got box86 to work (big learning curve) and now run Word 97 (my all-time favorite wp), npopuk (I really dislike geary), and HanDBase.

Jake

Edit: Screenies and brief how-to: https://forum.pine64.org/showthread.php?tid=18388&highlight=xfce (I've since solved top-row special character issues, etc. Everything works swimmingly)

Edited by Jake 2023-07-22 6:38 PM
 Top of the page
stingraze Page Icon Posted 2023-07-23 9:52 AM
#
Avatar image of stingraze
Subscribers
H/PC Vanguard

Posts:
3,685
Location:
Japan
Status:
@Jake

Thank you for the information. I currently use postmarketOS as my OS.
Wow! x86 working with Word 97. That is really nice.

Maybe I will switch to xfce under Manjaro Phosh someday to test it out.

Edited by stingraze 2023-07-23 9:53 AM
 Top of the page
Jake Page Icon Posted 2023-07-23 6:41 PM
#
Avatar image of Jake
Moderator
H/PC Vanguard

Posts:
2,831
Location:
Choking on the stench of ambition in Washington DC
Status:
I tried postmarketOS a while back, and I seem to recall a dearth of available software, but I was frantically distro-hopping, so I may be confusing it with another OS. Re: box86 -- if postmarketOS is debian-based, you could, I believe, set up box86.

Jake
 Top of the page
stingraze Page Icon Posted 2023-07-23 11:35 PM
#
Avatar image of stingraze
Subscribers
H/PC Vanguard

Posts:
3,685
Location:
Japan
Status:
@Jake

Thank you, I will see if postmarketOS can run box86.
I found the GitHub repository of it, so maybe I can build it.. haha

-stingraze
 Top of the page
Jake Page Icon Posted 2023-07-24 3:12 AM
#
Avatar image of Jake
Moderator
H/PC Vanguard

Posts:
2,831
Location:
Choking on the stench of ambition in Washington DC
Status:
Let me know if/when you're about to begin; I've picked up some pointers along the way. I found the process quite complicated.

Jake
 Top of the page
stingraze Page Icon Posted 2023-07-24 10:39 AM
#
Avatar image of stingraze
Subscribers
H/PC Vanguard

Posts:
3,685
Location:
Japan
Status:
@Jake

Thank you. I will!
 Top of the page
Jump to forum:
Seconds to generate: 0.187 - Cached queries : 70 - Executed queries : 10