1827458 Members
6019 Online
109965 Solutions
New Discussion

(Un) wanted scripts

 
Rushank
Super Advisor

(Un) wanted scripts

Hello,

In my environment here we use hundreds of scripts in different boxes. Most of them run by maestro schedular and some of them via cron jobs. I'm on cleaning up the system but want to know what scripts are really being used now. There are many unwanted files/scripts and I want to take them out. And most these scripts created 4-5 years back! These are mix of Ksh, perl, c.
My question is there any way I can check which are the scripts really being used now..?
Thanks
8 REPLIES 8
James R. Ferguson
Acclaimed Contributor

Re: (Un) wanted scripts

Hi:

If you assume that nothing or no one accesses the files unless it is to actually run them, then you could examine the last access timestamp:

# find /directory -xdev -atime +365 -exec ls -l {} \;

In this example, a 'ls -l' of files in "/directory" *not* accessed in the last 365 days would be returned.

Regards!

...JRF...
linuxfan
Honored Contributor

Re: (Un) wanted scripts

Hi Rushank,

Aah cleanup, its a dirty job but somebody's got to do it ;-). I don't know if there is a simple solution to this one.

There could be situations that some of these scripts are not being within other scripts, so you will have to be careful when removing some of these. How many scripts are we talking about here, 10,20, 100?

The other thing which seemed to have worked for me in the past is, check if any of the scripts are run in cron, or if any other scripts are running these, if not move them to a temp directory. Someone would be complaining if they are using them and don't find it, but i would suggest talking to your users if there is any possibility that they will be using them. Wait for a certain period and delete them if no one complains but do take backups before you delete them.

Are only the sysadmins using these scripts or the users are using them too?

-Good Luck
Ramesh
They think they know but don't. At least I know I don't know - Socrates
James R. Ferguson
Acclaimed Contributor

Re: (Un) wanted scripts

Hi again:

...and if my suggestion above meets your criteria, you could:

# find /directory -xdev -type f -atime +365 -exec rm {} \;

...to *remove* files in "/directory" that haven't been accessed in 365-days or more.

...JRF...
Santosh Nair_1
Honored Contributor

Re: (Un) wanted scripts

Just my two cents...I would go with James' suggestion especially if this is a production environment. The last thing you'd want is users screaming at you because their regularly scheduled scripts didn't run because they were (re)moved from their normal location.

Doing the find as shown above shows you if the file was accessed within the however many days (in the case above 365 days).

-Santosh
Life is what's happening while you're busy making other plans
linuxfan
Honored Contributor

Re: (Un) wanted scripts

Hi Rushank,

Ofcourse James has a better solution ;)
but one word of caution when you do a find with atime option it modifies the access time of the subdirectories, so you are okay for the files, but just wanted to inform you.

-Regards
Ramesh
They think they know but don't. At least I know I don't know - Socrates
Rushank
Super Advisor

Re: (Un) wanted scripts

Hello,

Thanks for your valuable tips. As I told you these scripts are very old but being used. I guess when these scripts being executed by maestro(schedular) or therwise it doesn't not change the timestamp of the script. These scripts are used mainly by the users.
There are more than 500 scripts in one production server.
John Poff
Honored Contributor

Re: (Un) wanted scripts

Hello,

One trick you might try is to put a few lines of code at the beginning of each of the scripts that writes the script name and a date/time stamp to a log file so that you will have a record of when each script gets called. You could run that way for a few weeks and maybe get an idea of which scripts are actually being called. Then, instead of just 'rm'ing the scripts, you could leave a stub script in place that also records if that script got called.

JP
Mark Vollmers
Esteemed Contributor

Re: (Un) wanted scripts

Hi-

This may sound like a dumb question, and if so, I apologize, but can you just check out the scheduler (maestro) to see what is being run? you can crontab -l to see the scripts called directly (although scripts called within a script is a different matter...). Also, how much space are we talking here. You may have hundreds of scripts, but if each one is tiny, it may be cluttered but it might be best just to leave well enough alone. Just a thought.

Mark
"We apologize for the inconvience" -God's last message to all creation, from Douglas Adams "So Long and Thanks for all the Fish"