LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Keep track of when a script runs (https://www.linuxquestions.org/questions/linux-newbie-8/keep-track-of-when-a-script-runs-4175441328/)

neoanomally 12-13-2012 11:25 AM

Keep track of when a script runs
 
There is a perl script that runs on this webserver whenever a user does something. Is there a way I log when that script runs or do something to track time and the amount of times the script runs?

Thanks,

shivaa 12-13-2012 11:57 AM

You can check appropriate system logs. Since every OS maintains logs at different locations, so it depends upon which OS this webserver has? Also you can check /home/username/.bash_history file to check history of commands run by that user.

neoanomally 12-13-2012 12:17 PM

I should have specified the restrictions I have. The permissions on the server are that one group has access to apache, and a separate group is the only group that has root access. I only have access to my directory and the directory for my website, this is stored on the web server. I could request access to logs, but that could take weeks with Christmas right around the corner. Is there a way to manually log things, like over a 2 day period? Thanks, again.

shivaa 12-13-2012 12:49 PM

Which distro i.e. operating system is there in webserver? To check, login on webserver and invoke:
Code:

uname -a
As far as I remember, a normal user can read common system logs. But as I said which distribution is there.. perhaps then people can better help you.
Also do you want to check script run logs for yourself or any other user?

FYI, system logs contains many type of log files (in Linux, common logs are maintained in /var/log/.... directory. In Solaris it's in /var/adm/... directory). Also a webserver may maintain it's logs somewhere else (I am not sure).
In the meantime, you can try:
Code:

grep <username> /var/log/*
OR
grep <username> /var/adm/*

One more thing, /home/username/.bashrc_history, contains a list of all commands user has invoked, so you can check that also.

neoanomally 12-13-2012 01:03 PM

Thank you very much for the commands. I am able to look up the commands that I have run, but I get a "Permission denied" accessing the specific logs in the log folder. I guess I could just add to that perl script so that the end it concatenates the system time to a file. The company keeps a tight lock on permissions within the server.

Server is Red Hat 4.. 2.6.9-89.ELsmp

shivaa 12-13-2012 02:14 PM

If you do not have permissions, then it cannot help. But still you can do:-

First check /home/username/.bash_history, using (Note: it will not show time of script run, but at least will tell you how many times script has run):-
Code:

grep "<scriptname.pl>"  /home/username/.bash_history
Then check system logs again as:-
Code:

awk '/<scriptname.pl>/ && /<username>/ {print $0}' /var/log/messages*
It will list all logs entries (if available in it) when user <username> run the script. Similarly you can invoke same command for other log files as well. Take a note, in these commands, just replace the filename (marked in green) to check other log files.

neoanomally 12-13-2012 04:15 PM

Thank you very much. That was what I was looking for. After much time I finally found it. Thanks again.


All times are GMT -5. The time now is 01:15 PM.