Quantcast
Viewing all articles
Browse latest Browse all 17828

Scripting with wildcards?

I am writing some scripts to make permission adjustments for server hardening on RHEL6. I am getting a file list from /etc/rsyslog.conf and using that as arguments for chmod. The issue I'm running into is that one of the lines uses a wildcard. For this reason, the script does not act as expected. I added a line to verify the file exists and if not, create it. When it hits this line, it removed the rest of the files from the /etc/modprobe.d directory. Does anyone have an idea on how I can filter out this line when I test if the files exist?

This is the script I have come up with thus far:

 fList=`grep -v "^#" /etc/rsyslog.conf | awk '{print $2 }' | grep "^/\|^-/"` for F in $fList do if [[ ${F:0:1} != "/" ]] then file_path="${F:1}" else file_path="$F" fi echo $file_path if [ ! -e $file_path ] then if [[ $file_path != *"\*"* ]] then touch "$file_path" fi fi chown -f -c root:root $file_path chmod -f -c 600 $file_path done 

edit: Added code and spelling

edit2: Finalized script for reference in case anyone else would like to use it or alter it for their own purposes

submitted by lima3whiskey
[link][16 comments]

Viewing all articles
Browse latest Browse all 17828

Trending Articles