I got a folder /srv/log/ in linux server where I have subfolders with the server names:
server1 server2 server3 server4
I need a command which will show me what is inside of those folders, but only specific ones which i have in text file "del_list":
server2 server4
I am trying to use a loop:
for i in `cat del_list`; do `ls /srv/log/$i/`; done
but it showes me only part of those servers and error:
-bash: folder1: command not found
-bash: folder2: command not found
but there are many other folders:'folder2, folder3' there but i cannot list them using my command, what I do wrong here?
CodePudding user response:
for i in `cat del_list`; do ls /srv/log/$i/; done
without the backtick around the command after the do
CodePudding user response:
If you can run a python scrpit:
#! /usr/bin/python3
import subprocess
import os
with open("del_list", "r") as f:
data = f.read().split(" ")
for file in data:
filepath = "/srv/log/" file
if os.path.isdir(filepath):
subprocess.check_call("ls " filepath, shell=True)
else:
print("Path " filepath " not exist!")