LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-23-2012, 06:11 AM   #1
Mr. Alex
Senior Member
 
Registered: May 2010
Distribution: No more Linux. Done with it.
Posts: 1,238

Rep: Reputation: Disabled
[bash] Self-terminating script


Hi.
In my IceWM startup script I have:
Code:
[[ $(ps ax | grep "[s]cript-disable-screensaver") ]] || /all/script-disable-screensaver.sh &
And in that script I have:
Code:
#!/bin/bash

while true
do
  sleep 400
  xset -dpms
  xset s off
  xset s noblank
done
Because X forgets those settings over time and turns on screensaver.

The problem is that when I terminate X, script continues to work and on next iteration starts to output errors that screen is not found. How can I make this script to self-terminate if one more iteration comes and X is not running?
 
Old 08-23-2012, 06:37 AM   #2
byannoni
Member
 
Registered: Aug 2012
Location: /home/byannoni
Distribution: Arch
Posts: 128

Rep: Reputation: 36
You could try this, but it's probably not ideal:
Code:
while [ ! -e ~/stop_x ]
do
  sleep 400
  xset -dpms
  xset s off
  xset s noblank
done
To stop the script:
Code:
touch ~/stop_x
 
Old 08-23-2012, 09:14 AM   #3
Mr. Alex
Senior Member
 
Registered: May 2010
Distribution: No more Linux. Done with it.
Posts: 1,238

Original Poster
Rep: Reputation: Disabled
I wish it could stop itself automatically.
 
Old 08-23-2012, 09:23 AM   #4
byannoni
Member
 
Registered: Aug 2012
Location: /home/byannoni
Distribution: Arch
Posts: 128

Rep: Reputation: 36
Quote:
Originally Posted by Mr. Alex View Post
I wish it could stop itself automatically.
Hmm... what is the name of the X process on your computer?
 
Old 08-23-2012, 09:33 AM   #5
Mr. Alex
Senior Member
 
Registered: May 2010
Distribution: No more Linux. Done with it.
Posts: 1,238

Original Poster
Rep: Reputation: Disabled
This I suppose
Code:
alex      1108  0.0  0.0   3568   752 tty1     S+   15:45   0:00 xinit /home/alex/.xinitrc -- /etc/X11/xinit/xserverrc :0 -auth /tmp/serverauth.3SRiJFw2wy
 
Old 08-23-2012, 09:40 AM   #6
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,326

Rep: Reputation: 920Reputation: 920Reputation: 920Reputation: 920Reputation: 920Reputation: 920Reputation: 920Reputation: 920
this mite work
Code:
while [ "`pgrep X`" ]
do
  sleep 400
  xset -dpms
  xset s off
  xset s noblank
done
 
1 members found this post helpful.
Old 08-23-2012, 09:47 AM   #7
byannoni
Member
 
Registered: Aug 2012
Location: /home/byannoni
Distribution: Arch
Posts: 128

Rep: Reputation: 36
Perhaps:
Code:
while [ "`pidof X`" ]
do
  sleep 400
  xset -dpms
  xset s off
  xset s noblank
done
Or:
Code:
while [ "`pidof xinit`" ]
do
  sleep 400
  xset -dpms
  xset s off
  xset s noblank
done
 
1 members found this post helpful.
Old 08-23-2012, 12:38 PM   #8
Mr. Alex
Senior Member
 
Registered: May 2010
Distribution: No more Linux. Done with it.
Posts: 1,238

Original Poster
Rep: Reputation: Disabled
Thanks, I'll check 'em out.
 
Old 08-23-2012, 01:36 PM   #9
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Arch
Posts: 10,031

Rep: Reputation: 3202Reputation: 3202Reputation: 3202Reputation: 3202Reputation: 3202Reputation: 3202Reputation: 3202Reputation: 3202Reputation: 3202Reputation: 3202Reputation: 3202
Please remember that while itself is a function and will read the exit code of the previous command, hence if X is not running either pidof or pgrep will return an error,
so we can just use:
Code:
while pidof X
do

OR

while pgrep X
do
You may wish to redirect the output to null
 
2 members found this post helpful.
Old 08-23-2012, 01:38 PM   #10
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,326

Rep: Reputation: 920Reputation: 920Reputation: 920Reputation: 920Reputation: 920Reputation: 920Reputation: 920Reputation: 920
these commands mite also help:
Code:
[schneidz@hyper abg]$  xwininfo
[schneidz@hyper abg]$ sudo  xdg-screensaver suspend    0xe00082
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
How this bash works? - Terminating openbox when the app exits? deckoff Programming 3 05-29-2012 02:05 AM
How to get some bash scripts into a simple bash script with some echo and if statement. y0_gesh Programming 3 03-01-2012 10:46 AM
SSH connection from BASH script stops further BASH script commands tardis1 Linux - Newbie 3 12-06-2010 09:56 AM
[SOLVED] Using a long Bash command including single quotes and pipes in a Bash script antcore Linux - General 9 07-22-2009 12:10 PM
Not terminating bash script TheIrish Programming 1 11-13-2008 12:36 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:08 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