Operating System - HP-UX
1828215 Members
2316 Online
109975 Solutions
New Discussion

Re: Help needed to finish script

 
SOLVED
Go to solution
Rudi Martin
Advisor

Help needed to finish script

Hi there people

This command is part of a script I'm busy with -
cp /sdata/files/log/sabscan.l09 /sjtds/home/sabfiles/plp13.`date '+%d%m%y'`

Now , the sabscan.l09 file is an ever increasing , master file , but I need to add a command to my line that will only remove all the day's stuff and put it into the new plp12.(today's date) file. The command cannot use a specified date , as this is gonna run in a cron daily , so it's gonna update and create files daily.

Please help me URGENTLY !!!

Thank you
4 REPLIES 4
Jakes Louw
Trusted Contributor

Re: Help needed to finish script

How about:
touch /sjtds/home/sabfiles/plp13.`date '+%d%m%y'` {create empty new daily file}

cat /sdata/files/log/sabscan.l09 >> /sjtds/home/sabfiles/plp13.`date '+%d%m%y'` {append data to new file}
cat /dev/null > /sdata/files/log/sabscan.l09 {empty master file}

Trying is the first step to failure - Homer Simpson
G. Vrijhoeven
Honored Contributor

Re: Help needed to finish script

Hi,

Is there a date entry is tyhe master file? if so you can do issue a date command that has the same output as in the file and do a awk script that prints all entrys after the date string and redirect it to todays file.

so:
VAR=$(date '+%d%m%y)
cat /sdata/files/log/sabscan.l09 | awk -v date=$VAR '/$VAR/ {start=1}
start=1 {print}'>>/sjtds/home/sabfiles/plp13.`date '+%d%m%y'`



HTH,

Gideon

PS. did not test this so may need to make adjustments to get it working.
Mark Grant
Honored Contributor
Solution

Re: Help needed to finish script

This isnæt possible without knowing if your file has a date in it and which format that date is in. If each line in your file has "month day" then you would only need to

grep `date +"%m %d"` /sdata/files/log/sabscan.l09 > /sjtds/home/sabfiles/plp13.`date '+%d%m%y'`

However, if there is no date in there at all then you are going to have to set up a cron job that moves sabscan.l09 to a backup file every day. Something like this

cat sabscan.l09 >> sabscan.l09.history && > sabscan.l09

Then you can use your normal script as sabscan.l09 will only ever contain todays data and sabscan.l09.history will contain all your previous days informatio
Never preceed any demonstration with anything more predictive than "watch this"
Rudi Martin
Advisor

Re: Help needed to finish script

Thanx Mark

grep `date +"%d%m% y"` /sdata/files/log/sabscan.l09 > /sjtds/home/sabfiles/plp13.
`date '+%d%m%y'`

working like a bomb !

Cheers