can I delate first line in a file without opening a file.
Normal unix "sed -i '1d' $path/cash.log" command is working fine, but my windows application not supporting latest version of sed, I also tried to download latest version of sed.exe but failed to find one.
I am in a process of implement a buffer mechanism using following script
#!/bin/sh
path=C:/APPS/Tivoli/bin/w32-ix86/TME/TEC/scripts
set -x
exec 2> $path/SMS_LOG1.log
Cash_count=`more $path/cash.log |wc -l`
while [ "$Cash_count" != "0" ]
do
sms=`head -1 $path/cash.log`
echo "#MSG#$sms" >>$path/output
sleep 5
sed -i '1d' $path/cash.log
Cash_count=`more $path/cash.log |wc -l` #echo "Cash_count: $Cash_count"
done < $path/cash.log
$path/cash.log is a cash file, I can't rename it because it content is loaded by another script
This script will send SMS until cash.log file become empty also it will continue check for the messages, start sending sms as soon as the message comes
Script can only take first line of the cash.log file and send SMS
Then I have to delete the first line, other wise script will always send same message only
$path/cash.log is a cash file, I can't rename it because it content is loaded by another script
This script will send SMS until cash.log file become empty also it will continue check for the messages, start sending sms as soon as the message comes
Script can only take first line of the cash.log file and send SMS
Then I have to delete the first line, other wise script will always send same message only
#!/bin/sh
path=C:/APPS/Tivoli/bin/w32-ix86/TME/TEC/scripts
while :
do
if [ -f $path/cash.log ]
then
mv $path/cash.log $path/cash.new
while read sms
do
echo "#MSG#$sms" >>$path/output
done < $path/cash.new
rm $path/cash.new
fi
done
My main script doesn't read the file cash.log, it only append SMS message to cash.log (messages format are given below).
Then the second script read the first line of cash.log ( i.e. first line �NOC-Alert:ITM_Linux_System_Statistics 06/25/2007 05:19:59-OPEN-CRITICAL-db21.1-High System thrashing - Pages paged in per second is 6518.00 and Pages paged out per second is 48.00�) send this to SMS modem (for testing new script I just redirect to $path/output)
Waite for some time and delete the first line from cash.log
Again it read the first line (this time second one i.e. NOC-Alert:APCupsOnBattery 06/25/2007 11:28:07 AM-OPEN-CRITICAL-chi2-APC(40KVA) UPS - A: UPS: On battery power in response to an input power problem) and execute the same
Second script will send SMS until cash.log become empty.
##############
$More cash.log
NOC-Alert:ITM_Linux_System_Statistics 06/25/2007 05:19:59-OPEN-CRITICAL-db21.1-High System thrashing - Pages paged in per second is 6518.00 and Pages paged out per second is 48.00
NOC-Alert:APCupsOnBattery 06/25/2007 11:28:07 AM-OPEN-CRITICAL-chi2-APC(40KVA) UPS - A: UPS: On battery power in response to an input power problem.
NOC-Alert:APCupsOnBattery 06/25/2007 12:52:50 PM-OPEN-CRITICAL-chi2-APC(40KVA) UPS - A: UPS: On battery power in response to an input power problem.
NOC-Alert:ITM_Linux_System_Statistics 06/25/2007 14:19:59-OPEN-CRITICAL-db02-High System thrashing - Pages paged in per second is 1710.00 and Pages paged out per second is 48.00.
NOC-Alert:ITM_ManagedSystem 06/25/2007 15:16:01-OPEN-FATAL-PW002-The Server Primary:PW002:NT is offline.
NOC-Alert:APCupsOnBattery 06/25/2007 03:31:22 PM-OPEN-CRITICAL-SNT01-APC(40KVA) UPS - A: UPS: On battery power in response to an input power problem.
NOC-Alert:APCupsOnBattery 06/25/2007 03:31:23 PM-OPEN-CRITICAL-PCSNT02-APC(40KVA) UPS-B: UPS: On battery power in response to an input power problem.
NOC-Alert:ITM_ManagedSystem 06/25/2007 15:16:01-OPEN-FATAL-PW002-The Server Primary:PW002:NT is offline.