Applying different commands at different location
Question: I am working in Ubuntu. I have a bunch of commands (say 10 commands like cmd1,
cmd2, cmd3..............cmd10)

I want to write a python script, which can achieve the following:

It should traverse through the directory structure and apply a command at
particular directory path. The location and the commands are already known to
me.

Here is the example how, I want the script to operate.

    
    
    /local/mnt/myspace/sample1$ cmd1
    /local/mnt/myspace/sample2$ cmd2
    /local/mnt/myspace$ cmd3
    /local/mnt$cmd4
    /local/mnt/myspace/sample9$ cmd 8
    /local/mnt/myspace/sample3$ cmd10
    

can someone please help on this.


Answer: Maybe something like this:

    
    
    import subprocess
    import os
    jobs=[
        ('/local/mnt/myspace/sample1', 'cmd1'),
        ('/local/mnt/myspace/sample2', 'cmd2'),
        ('/local/mnt/myspace', 'cmd3'),
        ('/local/mnt', 'cmd4'),
        ('/local/mnt/myspace/sample9', 'cmd', '8'),
        ('/local/mnt/myspace/sample3', 'cmd10'),
    ]
    
    for job in jobs:
        print "In", job[0], "executing", job[1:]
        os.chdir(job[0])
        subprocess.Popen(job[1:]).wait()
    

(just a quick shot)

Look how I have "abused" the apparent mistake at cmd 8 to show how to call
programs which take parameters.

