LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian
User Name
Password
Debian This forum is for the discussion of Debian Linux.

Notices

Reply
 
Search this Thread
Old 04-07-2005, 06:52 PM   #1
mattz40
LQ Newbie
 
Registered: Mar 2005
Location: Chalottte NC
Distribution: Debian Squeeze 386
Posts: 18

Rep: Reputation: 0
Writing a shell script


I have a general question that probably most people reading this can answer:
I can write a shell script to run a simple program. The program in this case is 'unclutter' which makes the cursor disappear after not moving for 15 seconds or so. The problem is that I also want to run 'feh' which is a stripped-down image display program. My shell script looks like this:

#!/bin/bash
unclutter
feh -F D60 /home/imagedirectory

The problem is that unclutter is supposed to keep running, I guess it's a linux version of a windows 'terminate and stay resident' application. What happens is unclutter runs, but feh doesn't run until I start some other application or click on an icon or something else that seems to kick off feh.
Since what I'm building is a digital picture frame that is intended to run these things without any intervention, I'm stymied. I've been struggling with this for a month or so.

Also, if you could tell me where this script should go, I'd be in your debt. I'm running GDM, and KDE on the user that's intended to be the auto-login picture frame. Where do I put this script to run, so that it runs after all the x-session and window manager stuff has run? Gnome has a nice session manager where I could add things, but the fullscreen image viewer didn't cover the menu bars, and you can't delete them all. In KDE it covers the menu bars, but there's no place to put the command to run the script at login (in the session manager).

I've struggled with this for a long time, you wizards are my last hope. Thanks in advance for any advice you can offer.
 
Old 04-07-2005, 06:57 PM   #2
tsphan
Member
 
Registered: Jan 2005
Location: Clackamas, Oregon, US
Distribution: Slackware 10.2
Posts: 154

Rep: Reputation: 30
the way you have it will have feh running once unclutter is done running.

i'm not sure what unclutter is, but if it's suppose to run in the background, add a " &" to the end of it

so it becomes:

#!/bin/bash
unclutter &
feh -F D60 /home/imagedirectory
 
Old 04-07-2005, 11:00 PM   #3
thegeekster
Member
 
Registered: Dec 2003
Location: USA (Pacific coast)
Distribution: Vector 5.8-SOHO, FreeBSD 6.2
Posts: 513

Rep: Reputation: 33
Re: Writing a shell script

Quote:
Originally posted by mattz40
...Also, if you could tell me where this script should go, I'd be in your debt. I'm running GDM, and KDE on the user that's intended to be the auto-login picture frame. Where do I put this script to run, so that it runs after all the x-session and window manager stuff has run? Gnome has a nice session manager where I could add things, but the fullscreen image viewer didn't cover the menu bars, and you can't delete them all. In KDE it covers the menu bars, but there's no place to put the command to run the script at login (in the session manager)...
KDE has an Autostart directory for each user in their home directory: $HOME/.kde/Autostart.........Putting the script in there (and making sure the script is executable) will cause it to run every time you log in to KDE..........



PS: If it starts before you want it to, you can always add a sleep command for however many seconds is needed before it starts the other commands ('sleep 10' will cause a 10-second delay)

Last edited by thegeekster; 04-07-2005 at 11:19 PM.
 
Old 04-08-2005, 11:05 AM   #4
mattz40
LQ Newbie
 
Registered: Mar 2005
Location: Chalottte NC
Distribution: Debian Squeeze 386
Posts: 18

Original Poster
Rep: Reputation: 0
Thank you very much for the advice, it's working as it's supposed to. Just one other thing to figure out (how to make this turn itself off after 3 or 4 hours) and I'm set. Thanks again.
 
Old 04-13-2005, 07:08 AM   #5
enemorales
Member
 
Registered: Jul 2004
Location: Santiago, Chile
Distribution: Ubuntu
Posts: 410

Rep: Reputation: 30
There is a "at" command which allows you to run applications in a specific time in future. There is also the $! variable, which contains the PID of the last background process excecuted.

You can use them to kill the "unclutter" process after 3 hours.

Yo can also kill it immediatly after feh ends, with something like this:

Code:
#!/bin/bash
unclutter &
feh -F D60 /home/imagedirectory
kill $!
 
Old 04-13-2005, 07:56 PM   #6
thegeekster
Member
 
Registered: Dec 2003
Location: USA (Pacific coast)
Distribution: Vector 5.8-SOHO, FreeBSD 6.2
Posts: 513

Rep: Reputation: 33
To have it close by itself after a period of time you can run a timer using a "while" or "until' loop which counts the seconds before terminating 'feh' automatically.......You will need to figure out how much time you want it to run, in seconds, first..............There are 3600 seconds in one hour, so 3 hours would be 10800 seconds (3600 * 3)............

Your code could look something like this:
Code:
#!/bin/bash

#Enter the number of seconds to run 'feh' before terminating it:
SECONDS=10800     # 10800 seconds equals 3 hours; 14400 seconds equals 4 hours

unclutter & 
# Start 'feh' and get it's process id number (PID):
feh -F D60 /home/imagedirectory && PID=$!

# Start the timer:
COUNT=0      # Initializing the counter for the timer
until [ $COUNT -ge $SECONDS ]
do
    sleep 1
    COUNT=$(( $COUNT + 1 ))
done 

# Time to terminate 'feh':
kill $PID
Read 'man bash' for more help in how things are done in bash...........


<EDIT>
BTW - In your case, a timer loop isn't really necessary.............Old habits die hard, as I tend to think in programming concepts..........

You can replace the timer loop with a simple sleep command, such as:
Code:
...

# Start the timer:
sleep $SECONDS

...
</EDIT>

Last edited by thegeekster; 04-17-2005 at 11:40 PM.
 
  


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
writing a shell script tchoua Linux - General 8 02-24-2005 07:18 PM
shell script writing ust Linux - General 6 01-24-2005 02:06 PM
writing my first shell script speedhead34 Linux - Newbie 4 12-20-2004 01:50 AM
help writing shell script np complete Linux - Newbie 6 08-30-2004 10:43 PM
Need Help in Writing a Shell Script. KptnKrill Linux - General 2 05-19-2003 06:44 AM


All times are GMT -5. The time now is 06:14 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration