bash - Find commands don't work in script only -
i have script searches specific locations .txt files , outputs results stdout, , file using tee command. @ least it's supposed to. i'm having strange issues however. here's code:
echo -e "${highlight}sensitive files:${off}" echo "## sensitive files:" >> $ofile file in $(cat $1); ls -lh $file 2>/dev/null; done | tee -a $ofile echo " " | tee -a $ofile echo -e "${highlight}suids:${off}" echo "## suids:" >> $ofile find / -type f \( -perm -04000 -o -perm -02000 \) -exec ls -alh {} \; 2>/dev/null | tee -a $ofile echo " " | tee -a $ofile echo -e "${highlight}owned root only:${off}" echo "## owned root only:" >> $ofile find / -type f -user root \( -perm -04000 -o -perm -02000 \) -exec ls -lg {} \; 2>/dev/null | tee -a $ofile echo " " | tee -a $ofile # text files echo -e "${highlight}text files:${off}" echo "## text files:" >> $ofile find /etc -type f -name *.txt -exec ls -lh {} \; 2>/dev/null | tee -a $ofile find /home -type f -name *.txt -exec ls -lh {} \; 2>/dev/null | tee -a $ofile find /root -type f -name *.txt -exec ls -lh {} \; 2>/dev/null | tee -a $ofile
the strange thing of commands work fine, except find searches .txt files @ bottom. none of commands work in script, yet if copy , paste them terminal , run exactly in script, work fine. how possible?
you need quote or escape *
in -name
patterns, otherwise shell tries expand , use expanded form in place in command line.
find /etc -type f -name '*.txt' -exec ls -lh {} \; 2>/dev/null | tee -a $ofile
and others being similar work
Comments
Post a Comment