I am looking for producing success/fail messages which are right aligned in bash. An example would be what apache2 produces on executing: sudo /etc/init.d/apache2 relo
Have a look at this thread, might be interesting : how to write a bash script like the ones used in init.d?
On Linux CentOS 6.5, i'm using the /etc/init.d/functions file:
#!/bin/bash
. /etc/init.d/functions # include the said file
action "Description of the action" command
exit 0
assuming command returns 0 on success, positive value if an error occurs.
To let the script be easy to read, i use a function call instead of the whole command.
Here is an example:
#!/bin/bash
. /etc/init.d/functions
this_will_fail()
{
# Do some operations...
return 1
}
this_will_succeed()
{
# Do other operations...
return 0
}
action "This will fail" this_will_fail
action "This will succeed" this_will_succeed
exit 0
resulting in:
(note : french locale ;-) )
Hope it'll help !