How to: Run All Shell / Perl / Python Scripts in a Directory

by Vivek Gite on October 12, 2007 · 2 comments

I've directory called /home/vivek/scripts/daily with over 25 perl / shell / python scripts for managing daily tasks. One day for some weird reason my crond died and I did not noticed the incident for 2 days.

Now crond is started and I'd like to run all those scripts. Here is a quick for loop running all scripts in a directory called ~/scripts/daily/:

for s in ~/scripts/daily/*;do [ -x $s ] && $s || : ;done

Above script will run each and every executable script it finds in a directory.

Update: As pointed out by jeff (see below), you can use run-parts shell script for the same purpose:
$ run-parts ~/scripts/daily/*

Featured Articles:

Share this with other sys admins!
Facebook it - Tweet it - Print it -

We're here to help you make the most of sysadmin work. So, subscribe!

{ 2 comments… read them below or add one }

1 Jeff Schroeder October 12, 2007

Or a *much* easier way:
run-parts ~/scripts/daily/

Your kung foo is good, but you will never beat the Tekken fighters.

Reply

2 vivek October 12, 2007

Thanks for the tip, post has been updated.

>Your kung foo is good, but you will never beat the Tekken fighters.
Heh .. Gotta love Tekken fighters!

Reply

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <blockquote> <pre> <a href="" title="">
What is 12 + 8 ?
Please leave these two fields as-is:
Are you a human being? Solve the simple math so we know that you are a human and not a bot.




Previous post:

Next post: