You are not logged in.

#1 2012-01-19 20:10:32

falmp
Member
Registered: 2011-11-18
Posts: 25

[SOLVED] Colors on stat_* functions (color in /etc/rc.d/* messages)

I noticed the colors on stat_* functions from /etc/rc.d/functions only works when the root user is running a command (or when a normal user runs with sudo). How to get the colors for my user when some other bash script includes and uses these functions?

For those which are not familiar with the stat_* functions, they're responsable for these messages:

$ /etc/rc.d/httpd restart
:: Restarting Apache Web Server                                                                                                                       [DONE]

P.S. I noticed the functions script checks the $USECOLOR variable, so I already tried setting USECOLOR=yes to my .bashrc with no success.

Last edited by falmp (2012-01-20 11:30:44)

Offline

#2 2012-01-19 20:14:35

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [SOLVED] Colors on stat_* functions (color in /etc/rc.d/* messages)

Can you post your script? Are you sourcing the functions?

# Exit current shell if user is not root
need_root() {
        (( EUID )) && printf 'You need to be root.\n' && exit 1
}

# Quit script if it's not running by root
# This can be disabled in scripts sourcing functions by setting NEED_ROOT=0
# A local call to need_root can be done to ensure part of script need root privilege
(( ${NEED_ROOT:-0} == 1 )) && need_root

Offline

#3 2012-01-19 20:27:36

falmp
Member
Registered: 2011-11-18
Posts: 25

Re: [SOLVED] Colors on stat_* functions (color in /etc/rc.d/* messages)

Sure.

#!/bin/bash

. /etc/rc.d/functions

case "$1" in
  start)
    ACTIVITY=uol
    if [ "$#" -eq 2 ]; then
      ACTIVITY=$2
    fi
    stat_busy "Starting hamster with activity $ACTIVITY";
    hamster-cli start $ACTIVITY
    stat_done
    ;;
    
  stop)
    stat_busy "Stopping hamster";
    hamster-cli stop
    stat_done
    ;;

  *)
    $HOME/.bin/hamster-day $1
esac

Last edited by falmp (2012-01-19 20:29:31)

Offline

#4 2012-01-19 21:02:27

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [SOLVED] Colors on stat_* functions (color in /etc/rc.d/* messages)

Have you tried setting' NEED_ROOT=0'?

Offline

#5 2012-01-19 21:21:49

falmp
Member
Registered: 2011-11-18
Posts: 25

Re: [SOLVED] Colors on stat_* functions (color in /etc/rc.d/* messages)

I didn't notice the NEED_ROOT part on your first post. smile I tried it now though with no different results (my hamster script works, I'm just not getting colored output).

Offline

#6 2012-01-19 22:49:41

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [SOLVED] Colors on stat_* functions (color in /etc/rc.d/* messages)

'USECOLOR="yes"' works for me.

NEED_ROOT=0
USECOLOR="yes"
. /etc/rc.d/functions

Last edited by karol (2012-01-19 23:02:03)

Offline

#7 2012-01-20 00:21:57

falmp
Member
Registered: 2011-11-18
Posts: 25

Re: [SOLVED] Colors on stat_* functions (color in /etc/rc.d/* messages)

Sorry, indeed it works. Thank you! big_smile I was missing an "export" on my USECOLOR=yes at .bashrc. roll

Last edited by falmp (2012-01-20 00:22:11)

Offline

#8 2012-01-20 10:06:38

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [SOLVED] Colors on stat_* functions (color in /etc/rc.d/* messages)

Please remember to mark the thread as solved :-)

Offline

#9 2012-01-20 11:30:58

falmp
Member
Registered: 2011-11-18
Posts: 25

Re: [SOLVED] Colors on stat_* functions (color in /etc/rc.d/* messages)

Done. smile

Offline

Board footer

Powered by FluxBB