convert /bash to /sh

Unitech Pt630d mobile computer, batch, 1...
July 20, 2010 at 03:28:19
Specs: Windows XP, 2gb
I realized today that actually I have to use normal Bourne shell (bin/sh) and not bash(bin/bash).

Could anyone PLEASE help me to adjust my script.I'm just getting so desperate....

below are my script, input and output example..

#!/bin/bash

dir=/home/input/test.log

msg=`tail -3 $dir`
msg1=`tail -1 $dir`
type=Report

status=Failed

name=${msg1%% is Failed *}
name=${name#ERROR: }


typeset -i dday


if [ ${#name} -eq ${#msg1} ]
then

date=${msg1##*on }
date=${date%%. *}

status=Success
name=${msg1%% successfully *}

datetime=${msg1##*ran on }
fi


datetime=${msg1##* on }
datetime=${datetime%% SST *}
time_end=${datetime##* }

hours1=(${time_end%:*})
hours2=${hours1%:*}

if [ $hours2 -le 12 ]
then
time_end="${time_end:0} AM"
else
time_end="$((hours2-12)):${time_end#*:} PM"
fi


datetime_start=${msg##* at }
datetime_start=${datetime_start%% SST *}
time_start=${datetime_start##* }

hours3=(${time_start%:*})
hours4=${hours3%:*}

if [ $hours4 -le 12 ]
then
time_start="${time_start:0} AM"
else
time_start="$((hours4-12)):${time_start#*:} PM"
fi

date=${msg1##*on }
date=${date%%. ErrorCode *}

df=(${msg1##* on})
dday=${df[2]}

if [[ $dday -le 10 ]]

then
myday="0${df[2]}"
else
myday="${df[2]}"
fi

logdate="${myday} ${df[1]} ${df[5]%.}"

echo "$name $logdate $time_start $time_end $type $status "

output:

report_name 08 Jul 2010 00:01:00 AM 3:15:00 PM Report Success

input:(test.log in : dir=/home/input)

if input is success:

report_name started at Thu Jul 8 00:01:00 SST 2010.
KL/SSL procedure successfully completed.
report_name successfully ran on Thu Jul 8 15:15:00 SST 2010.

really need your response asap..thanks


See More: convert /bash to /sh

Report •

#1
July 24, 2010 at 16:34:28
Are you sure? Assuming you're on a Linux system, most link sh as an alias for bash. Before you go through a lot of work "dumbing down" your script, make sure you actually have a real Bourne shell available. Secondly, why do you need to convert from bash (which is more or less a superset of sh) to sh? You're giving up a modern shell for an ancient one.

Report •
Related Solutions


Ask Question