LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 10-21-2005, 02:12 PM   #1
copolii
LQ Newbie
 
Registered: Feb 2005
Location: Richmond BC
Posts: 19

Rep: Reputation: 0
xset is unable to open display from within bash script


Hi evryone,

I'm trying to write a script that takes care of my lid close and open events on a laptop (Dell Inspiron 8600) the output from the script suggests that xset cannot open the display. When i run the script manually from a command prompt it works fine, but when i push the button and look at the log, this is what I see:

Quote:
[Fri Oct 21 12:05:39 2005] BEGIN HANDLER MESSAGES
Ran by root
Display is
xset: unable to open display ""
xset: unable to open display ""
[Fri Oct 21 12:05:39 PDT 2005] Turning display ON
xset: unable to open display ""
[Fri Oct 21 12:05:39 2005] END HANDLER MESSAGES
[Fri Oct 21 12:05:39 2005] action exited with status 0
[Fri Oct 21 12:05:39 2005] completed event "button/lid LID 00000080 00000002"
When i use xset -display 127.0.0.1:0.0 -q I get
Quote:
xset: unable to open display "127.0.0.1:0.0"
this is the script body:

Code:
#!/bin/bash

ME=`whoami`
echo "Ran by $ME"
echo "Display is $DISPLAY"

STATUS=`xset -q | grep -e 'DPMS is'`
if [ "$STATUS" == "DPMS is Disabled" ]
then
	echo "Enabling DPMS ..."
	xset +dpms
	
	if [ "$?" != "0" ]
	then
		echo "[`date`] An error occured while enabling DPMS"
		exit 1
	fi
fi

STATUS=`xset -q | grep 'Monitor is On'`

if [ "$STATUS" == "  Monitor is On" ]
then
	echo "[`date`] Turning display OFF"
	xset dpms force off
else
	echo "[`date`] Turning display ON"
	xset dpms force on
fi

unset STATUS
unset ME

exit 0
The reason im checking for whether I have to enable DPMS, is that no matter what i put in my xorg.conf file, still once X is up, dpms shows up as disabled.

Any ideas would be appreciated.
Mahram.
 
Old 10-22-2005, 07:25 AM   #2
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
Quote:
Display is
xset: unable to open display ""
In your script, you have this line.
Quote:
echo "Display is $DISPLAY"
I don't see anywhere that you have DISPLAY.
 
Old 10-22-2005, 04:19 PM   #3
copolii
LQ Newbie
 
Registered: Feb 2005
Location: Richmond BC
Posts: 19

Original Poster
Rep: Reputation: 0
yeah thats because I wanted to test and see if its set .... I read it as a suggestion somewhere ... I think my problem here starts before that
 
Old 10-22-2005, 06:26 PM   #4
copolii
LQ Newbie
 
Registered: Feb 2005
Location: Richmond BC
Posts: 19

Original Poster
Rep: Reputation: 0
PROBLEM SOLVED!!

Hi Guys,

the problem is solved, closing the laptop lid turns off the display, and and opening it, turns it back on.
solution is below:

add the lines below to any file in /etc/acpi/events/
You most likely already have something in there (for me it was sample.conf, I renamed it to acpid.conf so that it's more meaningful).
If you dont have anything in /etc/acpi/events/ create a file (i.e. acpid.conf or lid.conf) as long as the file ends in ".conf" the rest doesn't matter.
Code:
event=button/lid.*                                                     
action=/sbin/lidevent
once you added these lines, now you need the /sbin/lidevent file. this is just a shell script like this (it doesnt have be in /sbin or be called lidevent, you can put it anywhere you want and call it anything you want as long as you make the changes in the "action" line accordingly).
so copy the lines below and paste them in /sbin/lidevent
DONT OVERWRITE ANYTHING, if you already have a file with that name and at that location, find out WHAT it is, its best not to overwrite it and just save this script as something else.
Code:
#!/bin/bash

#-----------------------------------------------------------------------------#
# /sbin/lidevent                                                              #
# simple script to turn the display on or off when laptop lid is closed       #
# By Mahram Z.Foadi                                                           #
# Oct 22 2005                                                                 #
# thank you linuxquestions.org                                                #
#                                                                             # 
# the following lines must be present in your "/etc/acpi/events/" files. Some #
# systems already have a file called sample.conf in the mentioned directory   #
# rename it to something more meaningful (i.e. acpid.conf) and these lines to #
# the end of it  (you don't HAVE to rename it, you can even create a new file #
# and call it /etc/acpi/events/lid.conf with the 2 lines in it. If you intend #
# to put this file anywhere other than /sbin/lidevent, make sure you make the #
# proper changes in the "action" line below. For example if you are going to  #
# save this script as /usr/bin/mylid.sh then the action line should be:       #
# action=/usr/bin/mylid.sh                                                    #
# be sure both files are executable, writable, and owned by root ONLY because #
# the acpid daemon is most likely running as root in your system              #
#                                                                             #
#     ---- insert the two lines below in /etc/acpi/events/acpid.conf ----     #
# event=button/lid.*                                                          #
# action=/sbin/lidevent                                                       #
#-----------------------------------------------------------------------------#

# default display on current host
DISPLAY=:0.0

# find out if DPMS is enabled
STATUS=`xset -display $DISPLAY -q | grep -e 'DPMS is'`

# enable DPMS if disabled
if [ "$STATUS" == "  DPMS is Disabled" ]
then
	echo "Enabling DPMS ..."
	xset -display $DISPLAY +dpms
fi

# find out if monitor is on
STATUS=`xset -display $DISPLAY -q | grep 'Monitor'`

if [ "$STATUS" == "  Monitor is On" ]
then
	echo "[`date`] Turning display OFF"
	xset -display $DISPLAY dpms force off
else
	echo "[`date`] Turning display ON"		# shows up in log
	xset -display $DISPLAY dpms force on		# turn monitor on
	xset -display $DISPLAY s activate		# un-blank monitor
fi

#clean up
unset STATUS

# comment this line out if you're manually running this script from a shell (put a # in front of it)
unset DISPLAY

exit 0
If you don't have your laptop already configured to do this, you're missing out! you save A LOT of battery life with turning off the LCD when you don't need it.
Hope this helps someone out there.
MOD: Maybe this'd be more useful in the laptop forum than general? if you agree please move it accordingly.

Cheers,

Mahram
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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



Similar Threads
Thread Thread Starter Forum Replies Last Post
xset: unable to open display "mycomputer.mynetwork:0.0" nicolaeancuta Linux - Networking 2 07-13-2005 01:39 AM
xhost+ Unable to open Display atifrafi Linux - Software 1 06-26-2005 12:22 PM
unable to open display mrhldjc Fedora 1 04-04-2005 06:29 AM
xhost: unable to open display d_kote23 Fedora 1 06-03-2004 08:40 AM
xhost: unable to open display aqoliveira Linux - Networking 4 12-12-2003 04:36 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:58 AM.

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