LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 11-29-2023, 09:04 AM   #1
Alfred-Augustus
Member
 
Registered: May 2022
Posts: 91

Rep: Reputation: 7
Calling xmessage from rc.d/local not working


Can anyone explain why calling xmessage from rc.d/local does not work?
If I just run the following script manually from a terminal, then xmessage works.

I wrote the following to suspend the laptop when the battery level drops below 10%. Just before that, I want to display a pop-up message in front of the monitor.

Thanks!

Code:
$ cat /etc/rc.d/rc.local 

#!/bin/bash

  /etc/rc.d/rc.low-batt
Code:
$ cat /etc/rc.d/rc.low-batt 

#!/bin/sh

/home/ala/bin/low-batt &
Code:
$ cat /home/ala/bin/low-batt

#!/bin/sh

while sleep 60
do
   battlev=`cat /sys/class/power_supply/BAT0/capacity`

   if test $battlev -lt 10
     then
     xmessage -geometry 300x200+400+200 -title "Battery" \
         -buttons okay:1,quit:0 -default okay \
         "Batt level Low - Suspending" &
         sleep 5
         loginctl suspend
   fi

done

Last edited by Alfred-Augustus; 11-29-2023 at 09:10 AM.
 
Old 11-29-2023, 09:23 AM   #2
Petri Kaukasoina
Senior Member
 
Registered: Mar 2007
Posts: 1,803

Rep: Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484
You run xmessage as root, with no DISPLAY set. You could try to change 'xmessage' to 'XAUTHORITY=/home/ala/.Xauthority DISPLAY=:0 xmessage'. It could then work if you had logged in X.

But why do you want to run it as root? Just run it from ~/.xsession or similar, under your uid.
 
Old 11-29-2023, 09:57 AM   #3
Alfred-Augustus
Member
 
Registered: May 2022
Posts: 91

Original Poster
Rep: Reputation: 7
Quote:
Originally Posted by Petri Kaukasoina View Post

But why do you want to run it as root? Just run it from ~/.xsession or similar, under your uid.
I didn't really know what I was doing. I was just copying how Thinkfan starts up.

Now, I think I would want to be able to monitor battery and do "loginctl suspend" whether or not a X session has been started.

It would be nice to have that protection as soon as I boot up the laptop.

Last edited by Alfred-Augustus; 11-29-2023 at 10:33 PM.
 
Old 11-29-2023, 10:55 AM   #4
Tonus
Senior Member
 
Registered: Jan 2007
Location: Paris, France
Distribution: Slackware-15.0
Posts: 1,405
Blog Entries: 3

Rep: Reputation: 514Reputation: 514Reputation: 514Reputation: 514Reputation: 514Reputation: 514
I guess you could do a test on wich DISPLAY is up and send the message as well with the wall command.
 
Old 11-29-2023, 11:04 AM   #5
killerhippy
LQ Newbie
 
Registered: Jan 2021
Location: Germany
Distribution: debian
Posts: 22

Rep: Reputation: Disabled
I use a user systemd service to start a script which uses notify-send.
No need to tell DISPLAY or the like.

File ~/.config/systemd/user/backuphome.service
Quote:
[Unit]
Description=User service to run a backuphome script when the desktop is running
After=multi-user.target

[Service]
Type=oneshot
RemainAfterExit=true
StandardOutput=journal
ExecStart=/usr/local/bin/backup-home-init.sh start
ExecStop=/usr/local/bin/backup-home-init.sh stop
[Install]
WantedBy=default.target
 
Old 11-29-2023, 06:34 PM   #6
gus3
Member
 
Registered: Jun 2014
Distribution: Slackware
Posts: 490

Rep: Reputation: Disabled
Clearly, he's going with the flow...
 
Old 11-29-2023, 07:30 PM   #7
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,728

Rep: Reputation: 5919Reputation: 5919Reputation: 5919Reputation: 5919Reputation: 5919Reputation: 5919Reputation: 5919Reputation: 5919Reputation: 5919Reputation: 5919Reputation: 5919
Why not run it as a cron job? Since the output is not associated with a display:

* * * * * DISPLAY=:0 /home/ala/bin/low-batt (without the sleep loop)

As posted rc.local output is not associated with a terminal or the desktop. With the DISPLAY=:0 you could also run it via rc.local.
 
Old 12-01-2023, 07:51 AM   #8
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,374

Rep: Reputation: 2754Reputation: 2754Reputation: 2754Reputation: 2754Reputation: 2754Reputation: 2754Reputation: 2754Reputation: 2754Reputation: 2754Reputation: 2754Reputation: 2754
I used to do something similar using cron. You need to specify the full path name to xmessage in the cron script.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
xmessage: command not found Cirdan Linux - Newbie 4 09-01-2006 12:42 AM
wine can't find xmessage! Jubei Linux - Newbie 15 08-20-2003 10:44 AM
xmessage installation and howto x2000koh Linux - General 0 07-30-2003 09:09 PM
xmessage cut and paste mlenehan Linux - General 3 06-17-2003 03:27 PM
xmessage origin zindadilfaiz Linux - Networking 2 02-19-2003 03:10 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 04:51 PM.

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