Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4624514
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:08:26+00:00 2026-05-22T03:08:26+00:00

Pretty simple question (probably) but I guess since im new to python im not

  • 0

Pretty simple question (probably) but I guess since im new to python im not super sure about how os.system works.

Basically I have a for loop (thanks to some help from SO) that goes through all my directories and runs a shell script (like 120 something different shell scripts).

import os

root = '/foo/'

for directory, subdirectories, files in os.walk(root):
  for file in files:
     if os.path.splitext(file)[-1].lower() == '.sh':

Basically what I want to do is this (if it were in unix) (ignore the IP address but there will be an IP address each time)
sh run.sh 157.111.22.134 >> logfile.txt
THEN
sh remove.sh 157.111.22.134

I tried something like this

#!/usr/bin/env python

import os

root = "~/users/me"
ip = '157.111.22.134'
for directory, subdirectories, files in os.walk(root):
  for file in files:
     if os.path.splitext(file)[-1].lower() == '.sh':
       os.system('sh ' + os.path.join(directory, file) + ' ' + ip + '>>' ' log.txt')
       os.system('sh ' + 'remove.sh ' + ip)

but it complained about the second os.system (saying “unexpected indent”)

and im not even sure if I have it right? ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T03:08:27+00:00Added an answer on May 22, 2026 at 3:08 am

    You’re mixing up your indentation (spaces vs. tabs). Use python -tt to verify.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a probably pretty simple question but I am still not sure! Actually
This is seems like a pretty simple question, but I'm not sure if there's
Pretty simple question, I'm writing an XML document and i'm not sure how to
I'm pretty sure this is a simple question in regards to formatting but here's
This is probably (hopefully) a pretty simple question, but I can't seem to get
I know this is probably a pretty simple question, but i am trying to
So this is a pretty general question, but I've been wondering about it for
Pretty simple question: When i have a persistable object, it usually has a property
Question is pretty self explanitory. I want to do a simple find and replace,
I'd like to build a pretty simple plug-in for Visual Studio, but I don't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.