My Script does not die when I logout


Results 1 to 10 of 10

Thread: My Script does not die when I logout

  1. #1
    Join Date
    Feb 2002
    Location
    NC, USA
    Posts
    33

    My Script does not die when I logout

    I have a couple of scripts I use to change my desktop background every 10 minutes. setback2

    #!/bin/bash
    number=$RANDOM
    let "number2=number*50/32767"
    image=~/images/$number2.jpg
    echo $image > .screen.img
    if [ -x /usr/bin/X11/xv ] && [ -e $image ]
    then
    /usr/bin/X11/xv -maxp -quit -root $image
    fi

    randomly sets the background and setback3

    #! /bin/bash
    let "PID=$$"
    echo $PID > .pidfile.image
    while [ true ]
    do
    ~/bin/setback2
    sleep 600
    done

    sets the background every 10 minutes.
    My problem is that setback3 does not die when I log out.
    I have setback3 in my session startup. Is there a better way of doing this.
    Thanks for any help.
    AMD Athlon 1.3 Ghz
    Fedora Core 1
    512 MB RAM
    Nvida Riva TNT2 Video Card

  2. #2
    Join Date
    Sep 2002
    Location
    Boise, ID
    Posts
    653
    Are you starting the script with exec, or just putting the path/script on a line by itself in your .xinitrc? If you use exec it should terminate when the X session ends.
    Code:
    exec /path/to/your/scripts
    - Andy

    Obligatorydistro link.

  3. #3
    Join Date
    Feb 2002
    Location
    NC, USA
    Posts
    33
    Actually I am using the gome session manager to start the script for me when I login. I will try using the xinitrc file and see what happens.
    Thanks
    AMD Athlon 1.3 Ghz
    Fedora Core 1
    512 MB RAM
    Nvida Riva TNT2 Video Card

  4. #4
    Join Date
    Feb 2002
    Location
    NC, USA
    Posts
    33
    .xinitrc does not seem to work with gnome. How else does Gnome initialize its startup scripts?
    AMD Athlon 1.3 Ghz
    Fedora Core 1
    512 MB RAM
    Nvida Riva TNT2 Video Card

  5. #5
    Join Date
    Nov 2003
    Posts
    90
    assuming this gets started by the process that connects X -
    change the loop at the bottom

    Code:
    while [ true ] 
    do 
    ~/bin/setback2 
    ps - p $PPID >/dev/null 2>/dev/null
    if [ $? -eq 1 ] ; then
           exit;
    fi
    sleep 600 
    done
    $PPID is the parent pid of the process - ps fails if the pid does not exist.

  6. #6
    Join Date
    Apr 2001
    Location
    SF Bay Area, CA
    Posts
    14,947
    Don't do it as a pair of scripts.

    Do it using cron. Create a cron job that runs every 10 minutes. In the script that you run, first check to see that Gnome is running, then if it is, do your xv thing.

    ps -C gnome-session >/dev/null && /usr/X11R6/bin/xv -options will do this, with Linux's ps program. No ifs needed.

  7. #7
    Join Date
    Feb 2002
    Location
    NC, USA
    Posts
    33
    Thanks for the replies. Unfortunately it still does not work. I already had tried cron and it complained about not finding the current display.
    The $PPID was almost there! But the session startup menu kills itself I think so the process dies too. I have no clue about that.
    Back to the drawing board for me!
    AMD Athlon 1.3 Ghz
    Fedora Core 1
    512 MB RAM
    Nvida Riva TNT2 Video Card

  8. #8
    Join Date
    Feb 2002
    Location
    NC, USA
    Posts
    33
    I think I have it finally. I used bwkaz's idea of ps -C gnome-session and jim's idea of exiting when some conditin fails together to give me my cool desktop which changes every 10 minutes!

    #! /bin/bash
    let "PID=$$"
    echo $PID > .pidfile.image
    #while [ 1 -lt 2 ]
    while [ true ]
    do
    ~/bin/setback2
    ps -C gnome-session >/dev/null 2>/dev/null
    if [ $? -eq 1 ] ; then
    exit;
    fi
    sleep 600
    done

    Now that I have my desktop configured maybe i will actually do some work!!!
    AMD Athlon 1.3 Ghz
    Fedora Core 1
    512 MB RAM
    Nvida Riva TNT2 Video Card

  9. #9
    Join Date
    Apr 2001
    Location
    SF Bay Area, CA
    Posts
    14,947
    Originally posted by funnyjedi
    I already had tried cron and it complained about not finding the current display.
    Oh... I bet that's because cron jobs are run in non-interactive shells (i.e., shells that don't read either ~/.bash_profile or ~/.bashrc). If you export DISPLAY=:0.0 at the beginning of the script, that ought to help.

    Not that it matters, since you got it working anyway, but IMHO it's cleaner to do it in one script.

    *shrug*

  10. #10
    Join Date
    Feb 2002
    Location
    NC, USA
    Posts
    33
    As a personal choice I prefer one script too. I will try this one since it seems cleaner than using two. Thanks for the tip.

    It works! That is pretty cool. Thanks.
    Last edited by funnyjedi; 11-10-2003 at 09:21 AM.
    AMD Athlon 1.3 Ghz
    Fedora Core 1
    512 MB RAM
    Nvida Riva TNT2 Video Card

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •