Skip to content

Commit

Permalink
Revision and fix for issue #13
Browse files Browse the repository at this point in the history
  • Loading branch information
urbanware-org committed Oct 14, 2017
1 parent 3b12e5c commit 98c12e2
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 41 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@

CHANGELOG (SaLoMon)

Next version (outstanding)
Version 1.8.3 (2017-10-14)

* Revised the code to process the input files inside the main SaLoMon
as well as the analyzing and monitoring core script.
* Revised the output header inside the output core script (negligible
changes).
changes related to multiple input files).
* Revised the separator when processing multiple input files (replaced
the previous one with a line of hyphens).

# Fixed the bug that input file paths cannot contain any spaces.

Version 1.8.2 (2017-09-13)

* Revised the code in various SaLoMon components to allow multiple
Expand Down
29 changes: 24 additions & 5 deletions core/analyze.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,36 @@
analyze_input_file() {
check_patterns

for i in $input_file; do
tail "$i" &>/dev/null
spaces=0
for file in $input_file; do
temp=$(sed -e "s/^ *//g;s/ *$//g" <<< "$file")

grep "#" <<< "$temp" &>/dev/null
if [ $? -eq 0 ]; then
filepath="$(sed -e "s/#/\ /g" <<< "$temp")"
spaces=1
else
filepath="$temp"
spaces=0
fi

tail "$filepath" &>/dev/null
if [ $? -ne 0 ]; then
usage "No read permission on the given input file '$i'"
usage "No read permission on the given input file '$filepath'"
fi

if [ $spaces -eq 1 ]; then
temp=$(sed -e "s/\ /\*/g" <<< $filepath)
input_file_list="$input_file_list $temp"
else
input_file_list="$input_file_list $filepath"
fi

done

timestamp=$(date "+%Y%m%d%H%M%S%N")
temp_file="/tmp/salomon_${timestamp}.tmp"
paste -d "\n" $input_file | grep -v "^$" > $temp_file
paste -d "\n" $input_file_list | grep -v "^$" > $temp_file
input_file=$temp_file

count=0
Expand All @@ -35,7 +55,6 @@ analyze_input_file() {
fi

print_output_line "$line"

if [ $slow -eq 1 ]; then
sleep 0.$delay
fi
Expand Down
3 changes: 2 additions & 1 deletion core/global.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# ============================================================================

set_global_variables() {
version="1.8.2"
version="1.8.3"

arg_case=""
input_file=""
Expand All @@ -31,6 +31,7 @@ set_global_variables() {
highlight_all=0
highlight_cut_off=0
highlight_upper=0
interactive=0
prompt=0
slow=0
start_line=1
Expand Down
29 changes: 24 additions & 5 deletions core/monitor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,35 @@
monitor_input_file() {
check_patterns

for i in $input_file; do
tail "$i" &>/dev/null
spaces=0
for file in $input_file; do
temp=$(sed -e "s/^ *//g;s/ *$//g" <<< "$file")

grep "#" <<< "$temp" &>/dev/null
if [ $? -eq 0 ]; then
filepath="$(sed -e "s/#/\ /g" <<< "$temp")"
spaces=1
else
filepath="$temp"
spaces=0
fi

tail "$filepath" &>/dev/null
if [ $? -ne 0 ]; then
usage "No read permission on the given input file '$i'"
usage "No read permission on the given input file '$filepath'"
fi

if [ $spaces -eq 1 ]; then
temp=$(sed -e "s/\ /\*/g" <<< $filepath)
input_file_list="$input_file_list $temp"
else
input_file_list="$input_file_list $filepath"
fi

done

tail -n $start_line -F $input_file 2>/dev/null | while read line; do
tail -n $start_line -F $input_file_list 2>/dev/null| while read line; do
print_output_line "$line"

if [ $slow -eq 1 ]; then
sleep 0.$delay
fi
Expand Down
23 changes: 13 additions & 10 deletions core/output.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,19 @@ print_output_header() {
filepath=$(readlink -f $input_file)
print_line "${color_white}Input file:" "${color_yellow}$filepath"
else
input_file_list=""
desc="Input files:"
for file in $input_file; do
filepath=$(readlink -f $file)
temp="$files $filepath"
files="$temp"
temp=$(sed -e "s/^ *//g;s/ *$//g;s/#/\ /g" <<< "$file")
filepath=$(readlink -f "$temp")
if [ -z "$filepath" ]; then
continue
fi
print_line "${color_white}$desc" "${color_yellow}$filepath"
if [ ! -z "$desc" ]; then
desc=""
fi
done
input_file_list=$(sed -e "s/^\ //g" <<< $files)

print_line \
"${color_white}Input files:" "${color_yellow}$input_file_list"
print_line
fi

if [ "$color_file" = "" ]; then
Expand Down Expand Up @@ -202,8 +205,8 @@ print_output_line() {
if [ $seperator_line -eq 1 ]; then
grep "^==>.*<==$" <<< $1 &>/dev/null
if [ $? -eq 0 ]; then
temp=$((sed -e "s/==>//g" | sed -e "s/<==//g") <<< $1)
fp=$(readlink -f $temp)
temp=$(sed -e "s/==>//g;s/<==//g;s/^ *//g;s/ *$//g" <<< $1)
fp=$(readlink -f "$temp")
ln=$(printf -- "-%.0s" $(seq 0 80))
seperator="\e[1;30m--\e[0;37m[\e[1;33m$fp\e[0;37m]\e[1;30m$ln"
echo -e "$seperator\e[0m" | cut -c 1-113
Expand Down
2 changes: 1 addition & 1 deletion docs/usage_salomon.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ USAGE (salomon.sh)
inside the config sub-directories ('colors' and 'filters') of the
SaLoMon script directory.

3. Processing an input file
3. Processing input file

The following examples use a color config file. See section 2.3 for
details.
Expand Down
53 changes: 36 additions & 17 deletions salomon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ else
;;
-i|--input-file)
shift
input_file="$input_file $1"
temp=$(sed -e "s/^ *//g;s/ *$//g;s/\ /#/g" <<< $1)
input_file="$input_file $temp"
check_argument "-i/--input-file" "$input_file" "file"
shift
;;
Expand Down Expand Up @@ -153,6 +154,24 @@ else
esac
done

# Input file
temp=$(sed -e "s/^ *//g;s/ *$//g" <<< "$input_file")
input_file="$temp"

if [ -z "$input_file" ]; then
usage "No input file given"
fi

for file in $input_file; do
filepath=$(sed -e "s/^ *//g;s/ *$//g;s/#/\ /g" <<< $file)
if [ ! -e "$filepath" ]; then
usage "The given input file '$filepath' does not exist"
elif [ ! -f "$filepath" ]; then
usage "The given input file path '$filepath' is not a file"
fi
done

# Action to perform
if [ ! -z "$action" ]; then
if [ "$action" = "analyze" ]; then
follow=0
Expand All @@ -165,24 +184,12 @@ else
fi
fi

# Prompt before exit
if [ $follow -eq 0 ] && [ $prompt -eq 1 ]; then
usage "The analyzing mode does not support a prompt before exit"
fi

if [ -z "$input_file" ]; then
usage "No input file given"
fi

temp=$(echo "${input_file}" | sed -e 's/^ *//g;s/ *$//g')
input_file="$temp"
for i in $input_file; do
if [ ! -e "$i" ]; then
usage "The given input file '$i' does not exist"
elif [ ! -f "$i" ]; then
usage "The given input file path '$i' is not a file"
fi
done

# Color file
if [ ! -z "$color_file" ]; then
if [ ! -e "$color_file" ]; then
color_file="${color_dir}${color_file}"
Expand All @@ -197,6 +204,7 @@ else
fi
fi

# Highlighting
highlight_params=$(( highlight + highlight_all + highlight_upper ))
if [ $highlight_params -gt 1 ]; then
usage \
Expand All @@ -208,7 +216,7 @@ else
"The '--cut-off' argument can only be used with '--highlight-all'"
fi


# Filter pattern
if [ -z "$filter_pattern" ]; then
if [ "$arg_case" = "-i" ]; then
usage \
Expand Down Expand Up @@ -242,6 +250,8 @@ else
filter_pattern=$(sed -e "s/#/\ /g" <<< "$temp")
filter=1
fi
# Delay
grep -E "^[0-9]*$" <<< "$delay" &>/dev/null
if [ $? -eq 0 ]; then
temp=$delay
Expand All @@ -254,6 +264,8 @@ else
else
usage "The delay must be a number between 100 and 900"
fi
# Exclude pattern
if [ ! -z "$exclude_pattern" ]; then
grep "#" <<< "$exclude_pattern" &>/dev/null
if [ $? -eq 0 ]; then
Expand All @@ -266,6 +278,8 @@ else
-e "s/;/\n/g") <<< "$exclude_pattern")
exclude=1
fi
# Remove pattern
if [ ! -z "$remove_pattern" ]; then
grep "#" <<< "$remove_pattern" &>/dev/null
if [ $? -eq 0 ]; then
Expand All @@ -278,6 +292,8 @@ else
-e "s/;/\n/g") <<< "$remove_pattern")
remove=1
fi
# Wait on match
if [ -z "$wait_match" ]; then
usage "The wait value must not be empty"
else
Expand All @@ -290,16 +306,19 @@ else
usage "The wait value must be a number greater than zero"
fi
fi
# Check requirements
check_command grep 0 grep
check_command sed 0 sed
check_command tail 0 coreutils
fi
# Process the given input file
# Prepare output first
if [ $header -eq 1 ]; then
print_output_header
fi
# Finally, process the given input file
if [ $follow -eq 1 ]; then
monitor_input_file
else
Expand Down

0 comments on commit 98c12e2

Please sign in to comment.