LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Need help with creating a script-file (https://www.linuxquestions.org/questions/linux-general-1/need-help-with-creating-a-script-file-401936/)

kinetik 01-11-2006 03:11 AM

Need help with creating a script-file
 
OK, got a big task here, could use some help...


I want to write a script that will scan certain directories (let's call it /data/1/ /data/2/ and /data/3/) on certain machines (let's call it RH1, RH2, RH3, RH4 and RH5) for logfiles, delete logfiles that are older than the current date and make a copy of today's logfile (cp logfilecurrent.log logfilecurrent.log.bak), at the same time deleting previous backups.

The twist is that should certain logfiles contain keywords such as "error" or "exception", then it should not be deleted.

The further twist is that if a logfile contains any of these keywords, that the name, path and content be e-mailed to my address (kinetik@somewhere.com).


OK, what I thought of sofar:

On RH1:

cd /data/1/
ls -lahS


...and that's how far I got! Can anyone just prod me more or less in the right direction here or perhaps even offer some coding?



Thanks!

J_K9 01-11-2006 03:35 AM

Prod you in the right direction? Now, this I can do (as I have no scripting skills whatsoever) ;)

First of all, you may want to browse through O'Reilly's Linux Command Directory - already, maybe that's a bit too long to browse... better would be to eliminate the commands you need from this quick reference and then look them up at the LCD.

You may also want to check Sourceforge.net or Google for some code - especially for the emailing bit. Coding that would take you quite a while... :)

For the programming bit, I suggest you learn bash. There is a great tutorial on TLDP called Advanced Bash Scripting Guide which is very comprehensive and if you follow it you'll be programming in no time!

Assuming that the same shell is running on the machines, the commands will be exactly the same for all - so no need to code it differently for another machine. :D

Cheers,

-jk

kinetik 01-11-2006 03:38 AM

Thanks for the help J_K9!

Yep, all are using bash.

Any further advice still welcome everyone! The more help all of you can offer the more I'll be happy to take it. ...and give if I can one day help you out... :)

pixellany 01-11-2006 08:20 AM

Also on TLDP: Bash Guide for Beginners by Machtelt Garrels

Excellent book to buy: Classic Shell Scripting--O'Reilly

kinetik 01-11-2006 10:24 AM

Thanks for the help, appreciate it.


All times are GMT -5. The time now is 10:23 AM.