Redhat – how to write a Script to stop jboss and rename the corresponding log file in redhat

jbossredhatscriptingshell

i want to write a shell script to stop my currently running jboss applications(may more than one jboss running in one server) and rename the corresponding log files generated in the log directory.Renamed file must contain the time when the script is running,that will helps to identify that file.Please help me…

Best Answer

You can use logrotate as suggested by Ignacio. For example, the following configuration snippet shows how to logrotate the system messages file and reloading the syslogd process. You can use prerotate and postrotate to execute scripts/commands before and after rotating the log file respectively.

/var/log/messages {
   rotate 5
   weekly
   postrotate
        /usr/bin/killall -HUP syslogd
   endscript
}

For more info, check man logrotate.