Sed: -e expression #1, char 2: extra characters after command

Greetings..

getting the error while execution of the script, correct where i am missing

 
#!/bin/bash
DATE=`date +%Y-%m-%d:::%H:%M`
HOSTNAME=`hostname`
TXT="/log/temp.txt"
LOGPATH="/log1/commanlogs/"
IP=`/sbin/ifconfig | grep -i inet| head -n1| awk '{print $2}'| awk -F : '{print $2}'`
#To Check HTTP Instance
for di in abc abcd ;
do
ps -ef | grep $di | grep -v grep | grep root > /dev/null
if [ "$?" -ne "0" ]; then
count= grep $di $TXT | wc -l
if [ count -ne 0 ]; then
continue;
fi
echo $di >> temp.txt
DU=DOWN
D1=`date +%H-%M-%S`
LOG="$LOGPATH$HOSTNAME-$D1-HTTP-$di-Instance-Down"
echo "DATE $DATE" > $LOG
echo "IPADD $IP" >> $LOG
echo "HOSTNAME $HOSTNAME" >> $LOG
echo "STATUS $di is $DU" >> $LOG
echo "MSG $di-Instance" >> $LOG
echo "TV NONE" >> $LOG
else
sed -i "$di" $TXT
fi
done

Corrections:-

count=$( grep $di $TXT | wc -l )
if [ $count -ne 0 ]; then

still It's not working

Please be more specific, what error message are you getting?

Main goal of the scipt is to execute alert only one time in hour when https

services is down. below is the error when i execute the script with sh -x

script

sed: -e expression #1, char 2: extra characters after command

Tested your script with corrections I suggested, works fine for me! Set the debug and check:-

#!/bin/bash -xv

what's the objective of this?

sed -i "$di" $TXT

That will never yield a valid command in starndard sed.

sed abc /log/temp.txt
sed abcd /log/temp.txt

To the standard sed parser, both look like the beginning of an append command, but the a is improperly followed by a character sequence that is not a backslash-newline pair.

GNU sed will probably accept both, inserting after every line in the file a line consisting of the characters which follow the a .

Regards,
Alister

1 Like