Skip to content

alpacagh/bsfl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BSFL The Bash Shell Function Library

BSFL is a small Bash script that acts as a library for bash scripts. It provides a couple of functions that makes the lives of most people using shell scripts a bit easier.

THIS REPO IS A FORK OF google-code repo WITHOUT SIGNIFICANT CHANGES

Examples

Downloading and installing Nmap

#!/bin/bash

. ./bsfl

cmd "wget -q http://nmap.org/dist/nmap-5.51.tar.bz2"
cmd "tar xjf nmap-5.51.tar.bz2"
cd "nmap-5.51"
cmd "./configure"
cmd "make -j 3"
cmd "make install"

The output will look like this:

image

Example script

#!/bin/bash
    
. ./bsfl
    
LOG_ENABLED=y
LOG_FILE=my-log-file.log
    
START=`now`
log "-----------------------------------------------------------------"
log "This is my first log message it will not be displayed on screen."
msg "This is a display message that is also logged."
echo "Below is an empty messages"
msg 
msg_status "Raw status message." OK
msg_ok "OK message."
msg_not_ok "Not OK message."
msg_fail "Failed message."
msg_info "Informational message."
msg_warn "Warning message."
msg "This text is light blue." "$LIGHT_BLUE"
msg "This text is red." "$RED" 
msg "This text is neutral."
msg "This is a blue line with status." "$BLUE"
display_status OK
cmd "ls -al"
cmd "ls /blabla"
cmd "sleep 2"
STOP=$(now)
DURATION=$(elapsed $START $STOP)
msg "Duration is $DURATION seconds." "$GREEN"
SYSLOG_ENABLED=yes
msg "This message is logged to syslog"
FILE=/etc/passwd
if file_exists $FILE
then
    msg_ok "File /etc/passwd exists."
else
    msg_fail "File /etc/passwd is mssing."
fi  
echo a > replace.txt
echo b >> replace.txt
echo c >> replace.txt
str_replace_in_file b d replace.txt
VAR="a b c"
str_replace b d "$VAR"
check_status "$_" "$?"
ls > /dev/null
check_status "$_" "$?"
dir123 > /dev/null 2>&1
check_status "$_" "$?"

About

Automatically exported from code.google.com/p/bsfl

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages