How I can replace this command --need help

Hi,

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

Please help me on this.

Thanks in advance
Regards
Sudhish

awk ' NR > 1 { print > "newfile.back" }' currentfile

Hi,

awk ' NR > 1 { print > "newfile.back" }' currentfile

It is working fine, but I what to delete the first line since it is loop command I cant replace the file.
Thanks in advance

Regards
Sudhish

tail +2 input_file > output_file
It is working fine, but I what to delete the first line since it is loop command I cant replace the file.
Thanks in advance

If you had to process within a loop,
this might help,

awk command;
( you have the new file )
mv new_file old_file

Hi,
Let me explain my requirement

  1. $path/cash.log is a cash file, I can't rename it because it content is loaded by another script
  2. 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
  3. Script can only take first line of the cash.log file and send SMS
  4. Then I have to delete the first line, other wise script will always send same message only

Deletion of first line is the problem

Thanks in advance
Sudhish

Hi,

Let me explain my requirement

  1. $path/cash.log is a cash file, I can't rename it because it content is loaded by another script
  2. 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
  3. Script can only take first line of the cash.log file and send SMS
  4. Then I have to delete the first line, other wise script will always send same message only

Deletion of first line is the problem

Thanks in advance
Sudhish

You can try something like that (not tested) :

#!/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

Hi,

It is not working; I can't rename the file (cash.log) because another script output always feed SMS messages into it

Thanks in advance
Regards
Sudhish

You can't modify the file since another process is writing to it.
In fact, it's possible but it's impossible to guarantee the integrity of the file.

In which order do start the process reading the file and the manuscript reading this same file?

Hi,

Sorry for the delay response.

This is what the scripts does.

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.

Thanks in advance
Regards
Sudhish