Register
It is currently Sun Nov 23, 2014 2:43 am

How do I 'kill' a process in bash without display issues?


All times are UTC - 6 hours


Post new topic Reply to topic  [ 3 posts ] 
Author Message
 PostPosted: Mon Jul 06, 2009 7:45 pm   

Joined: Mon Jul 06, 2009 9:30 am
Posts: 8
Everyone,

I know ... this sounds like an easy one, but I have done my homework and tried tons of stuff. It doesn't work. This is not a typical "kill $pid" solution.

I want a script to run when the machine is booted, which will prompt the user to make some initial config settings. However, the user may only do this once - during installation, and the server will likely be headless after that. So, I need the script to timeout.

Here is my approach:

1. A script called launch.sh is executed from rc.local on each boot. All it does, is launch prompt.sh, grab its process ID and kill it after 5 seconds.

2. The prompt.sh script simply asks the user if they want to run a setup utility (called test.sh). If they don't respond in 5 seconds, the prompt.sh script is killed by launch.sh. If they respond with a 'Yes', then the prompt.sh script executes test.sh and then terminates. In this case, when launch.sh tries to terminate prompt.sh, it shouldn't be running anymore - so it doesn't matter.

3. The test.sh script should now be running if the user answered 'Yes' to the prompt.sh script.

Now, here is where things go wrong. When launch.sh terminates prompt.sh, it messes up the screen and the ability of the user to interact with the test.sh dialog.

Why?

The scripts are very short and simple. See below. Just edit the few paths and give it a whirl to see what I mean.

Thanks in advance to anyone who can help!

Eric

-----------------launch.sh---------------------------------------------------------------------
Code:
    #!/bin/bash
    # -----------------------------------------------------------
    # This launch.sh script will be executed by rc.local on boot.
    # -----------------------------------------------------------

    # -------------------------------------------
    # Execute prompt.sh and grab it's process ID:
    # -------------------------------------------

    /root/test/prompt.sh &

    pid=$!

    #----------------------------------------------------
    # Give the user 5 seconds to interact with prompt.sh:
    # ---------------------------------------------------

    sleep 5

    # --------------------------------------
    # Kill prompt.sh if it is still running:
    # --------------------------------------

    kill $pid

    exit 0



---------------------------prompt.sh-----------------------------------------------------------
Code:
    #!/bin/bash
    #
    # ---------------------------------------------------------------------
    # This script is executed by launch.sh. If the user has not responded
    # to the yes/no prompt in the set time, then launch.sh will terminate
    # this script so that the normal boot may continue.
    # ---------------------------------------------------------------------

    dialog --backtitle "Setup Utility" \
           --title     "Setup"         \
           --clear                     \
           --yesno     "\nDo you wish to execute the setup utility? \n\nNormal boot will continue in 5 seconds." 12 30

    case $? in
      0)
        /root/test/test.sh;;
    esac

    exit 0


---------------------------test.sh-----------------------------------------------------------
Code:
    #!/bin/bash
    #
    # ----------------------------------------------------------------------------
    # This script is launched by the prompt.sh script if the user answers 'yes'.
    # ----------------------------------------------------------------------------

    # ----------------------------------------------------------------------------
    # FUNCTIONS
    # ----------------------------------------------------------------------------

    function main {

      HOST_IP_ADDRESS=""
      HOST_NET_MASK=""
      HOST_GATEWAY=""
      HOST_DNS_1=""
      HOST_DNS_2=""
      GUEST_IP_ADDRESS=""
      GUEST_NET_MASK=""
      GUEST_GATEWAY=""
      GUEST_DNS_1=""
      GUEST_DNS_2=""

      dialog --backtitle "CIMonitor Setup Utility" \
             --title     "Network Settings" \
             --form      "Enter the IP address for each field:"          17 42 10 \
                         "Server  IP Address: " 1  1 "$HOST_IP_ADDRESS"  1  22 15  0 \
                         "Server  Net Mask  : " 2  1 "$HOST_NET_MASK"    2  22 15  0 \
                         "Server  Gateway   : " 3  1 "$HOST_GATEWAY"     3  22 15  0 \
                         "Server  DNS 1     : " 4  1 "$HOST_DNS_1"       4  22 15  0 \
                         "Server  DNS 2     : " 5  1 "$HOST_DNS_2"       5  22 15  0 \
                         "Manager IP Address: " 6  1 "$GUEST_IP_ADDRESS" 6  22 15  0 \
                         "Manager Net Mask  : " 7  1 "$GUEST_NET_MASK"   7  22 15  0 \
                         "Manager Gateway   : " 8  1 "$GUEST_GATEWAY"    8  22 15  0 \
                         "Manager DNS 1     : " 9  1 "$GUEST_DNS_1"      9  22 15  0 \
                         "Manager DNS 2     : " 10 1 "$GUEST_DNS_2"      10 22 15  0

    }

    # ----------------------------------------------------------------------------
    # MAIN
    # ----------------------------------------------------------------------------

    main

    exit 0


Top
 Profile  
 PostPosted: Thu Jul 09, 2009 10:01 am   

Joined: Mon Jul 06, 2009 9:30 am
Posts: 8
Everyone,

I never figured this out - but I did find a work around such that there is no process that must be killed.

Thanks,

Eric


Top
 Profile  
 PostPosted: Thu Jul 09, 2009 1:28 pm   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 567
dialog has a --timeout option.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP