Thursday, May 14, 2009

Script to log shutdown/reboot or runlevel change by users

Creating a script that updates the rc.local file and the .bashrc file for log the shutdown/runlevel change or reboot activity done by any user (after giving "su" command)


##- Updating the /etc/rc.local file
/bin/echo '/bin/echo `date +%Y-%m-%d\ %H:%M:%S\` System booted >> /var/log/reboot' >> /etc/rc.local

##- Updating .bashrc file for Log

/bin/echo "# Alias for logging the shutdown or runlevel change:" >> /root/.bashrc
/bin/echo 'alias shutdown="echo \`date +%Y-%m-%d\ %H:%M:%S\` System shutdown command by: \`who am i\` >> /var/log/reboot & shutdown" ' >> /root/.bashrc
/bin/echo 'alias reboot="echo \`date +%Y-%m-%d\ %H:%M:%S\` System rebooted by: \`who am i\` >> /var/log/reboot & reboot" ' >> /root/.bashrc
/bin/echo 'alias init="echo \`date +%Y-%m-%d\ %H:%M:%S\` System runlevel changed: by: \`who am i\` >> /var/log/reboot & init" ' >> /root/.bashrc
/bin/echo 'alias poweroff="echo \`date +%Y-%m-%d\ %H:%M:%S\` Poweroff command issued by: \`who am i\` >> /var/log/reboot & poweroff" ' >> /root/.bashrc
/bin/echo 'alias halt="echo \`date +%Y-%m-%d\ %H:%M:%S\` System Halted by: \`who am i\` >> /var/log/reboot & halt" ' >> /root/.bashrc
/bin/echo 'alias telinit="echo \`date +%Y-%m-%d\ %H:%M:%S\` System runlevel change: by: \`who am i\` >> /var/log/reboot & telinit" ' >> /root/.bashrc

//Lin u X u niL

No comments:

Post a Comment

tag ur valuable ideas below