LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 05-27-2011, 04:06 PM   #1
musonio
Member
 
Registered: Jun 2009
Distribution: PCLinuxOS
Posts: 33

Rep: Reputation: 15
bash script: wait for input from kdialog before doing sth.


The goal of the script is the following:
Whenever I leave my house, my wife comes to my computer to check her mails (She has two computers of her own but they have a dangerous operating system, so they have been banned from the internet).
She shuts down qbittorrent so as to download all her mails, and she forgets to execute it again on 98% of the times. End result: my computer is sometimes turned on for 10 hours doing absolutely nothing.

I had therefore two choices: a) get on my wife's nerves until she gets the problem or b) write a bash script.
If you are married, you will understand that bash scripts are easier to deal with than spouses.
Ergo, I wrote the following script:

Code:
#!/bin/bash -x

while true ; do

TH=$(pgrep thunder)

if [ $TH != [0] ] ; then
sleep 300s

else

    if [ -z "$(pgrep qbittorrent)" ] ;  then
	    kdialog --yesnocancel "QBitTorrent no se está ejecutando, ¿shall I?" 
	    ANSWER=$?
	    if [ $ANSWER = 2 ] ; then
		    exit
	    elif [ $ANSWER = 0 ] ; then
		    qbittorrent
	    elif [ $ANSWER = 1 ] ; then
		    echo 
	    else
		    qbitorrent

	    fi
    fi
fi

sleep 10s
done
I don't know how to make it wait for, say, 15 seconds, and, if no input from kdialog is received, run qbittorrent.

Any help?

Last edited by musonio; 05-27-2011 at 04:10 PM.
 
Old 05-29-2011, 12:22 AM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
The parent process could start a child shell running the kdialog, then sleep for 15 seconds. After 15 seconds, if the child was still running it could kill the child otherwise it could read the return value set by the child.

Alternatively you could switch from kdialog to yad, which has a richer feature set including a timeout.
 
1 members found this post helpful.
Old 05-29-2011, 07:15 PM   #3
musonio
Member
 
Registered: Jun 2009
Distribution: PCLinuxOS
Posts: 33

Original Poster
Rep: Reputation: 15
catkin:
using yad solved it:
Code:
yad --timeout 5 ...
I had never paid attention to it and unfortunately the wiki and info pages are not too clear, but it's great.
Thanks a lot.
 
Old 05-30-2011, 11:28 AM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
My pleasure
 
  


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
Making bash script WAIT after starting subshell mintybadger Programming 9 08-04-2011 04:49 AM
How to create a bash script to wait for wget to finish and then continue danlee Linux - General 14 05-30-2008 11:21 AM
How to make a script wait for input farmerjoe Linux - General 2 12-28-2004 05:18 AM
Make script wait for input farmerjoe Linux - General 4 12-28-2004 01:49 AM
bash-script won't wait for application to finish TLV Linux - Software 24 09-30-2004 11:18 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

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