Find the answer to your Linux question:
Results 1 to 5 of 5
Hi all, i been writting bash script for couple of months now, i was jus puzzled on how can i do this : Untitled.jpg If you look at wat i ...
  1. #1
    Just Joined!
    Join Date
    Jun 2008
    Posts
    5

    Bash scripting with status indication

    Hi all,

    i been writting bash script for couple of months now, i was jus puzzled on how can i do this :

    Untitled.jpg

    If you look at wat i wan is basically, having a statement being wrtting something like :
    Code:
    Daemon Started     [ Done ]
    Daemon Listening   [ Fault ]
    all in the same vertical line and horizontal line of that statement.

    today i could only do something like :
    Code:
    Daemon Started
                                         [Done]
    Daemon Listening
                                         [Fault]
    it basically in same vertical line but not in same horizontal line.
    it has to skip 1 line.
    i do it by adjusting "echo -e" & "echo -en"

    can someone explain how can i achieve something like picture above.

  2. #2
    Just Joined!
    Join Date
    Jan 2011
    Location
    Fairfax, Virginia, USA
    Posts
    94
    Hi, the mechanism for how the init.d scripts works changes on your distribution. In Redhat and Fedora, its done with a script in /etc/init.d calling /etc/rc.d/init.d/functions which has a bash function in it called deamon I think.

    Anyway, to achieve what you want, the left hand side could be done with something like:
    Code:
    echo -n Deamon
    then the right hand side could be done with something like:
    Code:
    echo Success
    If you want to color code it, you can follow this web page for examples:
    Bash Colours

  3. #3
    Just Joined!
    Join Date
    Jun 2008
    Posts
    5

    Thanks for reply

    Quote Originally Posted by BrianMicek View Post
    Hi, the mechanism for how the init.d scripts works changes on your distribution. In Redhat and Fedora, its done with a script in /etc/init.d calling /etc/rc.d/init.d/functions which has a bash function in it called deamon I think.

    Anyway, to achieve what you want, the left hand side could be done with something like:
    Code:
    echo -n Deamon
    then the right hand side could be done with something like:
    Code:
    echo Success
    If you want to color code it, you can follow this web page for examples:
    Thanks for replying,

    I have actually tried that but it doesnt really get a proper vertical line, example all i get is :

    Code:
    Starting Deamon      [Done]
    starting Listining to Deamon      [Fault]
    It is based on the length of characters on the left then only on the right prints out based on the tabs or spaces.
    but thats not what or how i would like to have it.
    i practically am trying to hv it in sync in 1 line

  4. #4
    Just Joined! jippie's Avatar
    Join Date
    May 2006
    Location
    Eindhoven, the Netherlands
    Posts
    76
    check printf manual page instead of using echo

  5. #5
    Linux Guru
    Join Date
    May 2011
    Posts
    1,843
    If you want to replicate the OK/FAILED messages at init (like in your posted pic), you could do something like:
    Code:
    #!/bin/bash
    
    # source function library
    . /etc/init.d/functions
    
    # run your prog/script/command
    action $"Running my prog: " /path/to/prog
    It will evaluate the exit code from your prog and show either OK or FAILED.

    If you want to do your own message, then just look at the /etc/init.d/functions and see what they do with RES_COL, MOVE_TO_COL and SETCOLOR_*

Posting Permissions

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