I have:
# runPath is the current path, commands is a list that's mostly irrelevant here
def ParseShellScripts(runPath, commands):
for i in range(len(commands)):
if commands[i].startswith('{shell}'):
# todo: add validation/logging for directory `sh` and that scripts actually exist
with open(os.path.join(runPath, 'sh', commands[i][7:]),"r") as shellFile:
for matches in re.findall("/^source.*.sh", shellFile):
print matches
However, I get this error:
Traceback (most recent call last):
File "veri.py", line 396, in <module>
main()
File "veri.py", line 351, in main
servList, labels, commands, expectedResponse = ParseConfig(relativeRunPath)
File "veri.py", line 279, in ParseConfig
commands = ParseShellScripts(runPath, commands)
File "veri.py", line 288, in ParseShellScripts
for matches in re.findall("/^source.*.sh", shellFile):
File "/usr/lib/python2.7/re.py", line 177, in findall
return _compile(pattern, flags).findall(string)
TypeError: expected string or buffer
Edit: adding some files as examples
#config.sh
#!/bin/bash
dbUser = 'user'
dbPass = 'pass'
dbSchema = ''
dbMaxCons = '4000'
#the shellFile I'm looking in
#!/bin/bash
source config.sh
OUTPUT=$(su - mysql -c "mysqladmin variables" | grep max_connections | awk '{print $4}')
if [[ ${OUTPUT} -ge ${dbMaxCons}]]; then
echo "Success"
echo ${OUTPUT}
else
echo ${OUTPUT}
fi
Basically what I want to accomplish is to search through all specefied files in the sh directory, and if any of them contain source*.sh (e.g., source config.sh), print that file (eventually I will be expanding it out and appending it to the top of the current file so that I can pass the single command-string via ssh.. but that's not relevant here I don't think.)
What am I doing wrong?
for matches in re.findall("/^source.*.sh", line) for line in shellfile: