Please help! I am preparing a Linux Script to move windows executable files from samba directory to quarantine directory. For safety, will use "file" command to determine if its executable. Anyone can help? Below is my trial script, but it just move everything, including non-executable.. any wrong with this?
cd path_of_samba_directory
for i in 'file -ib * | grep x-dosexec'; do
mv $i /tmp;
done
SAMBAPATH=/export/samba/quarantine
LIST=`ls $SAMBAPATH`
LOOKFOR="x-dosexec"
for i in $LIST; do
if (file -ib $i | grep $LOOKFOR > /dev/null 2>&1>/dev/null); then
echo $i has it
fi
done
Thanks kodak. I finally get it done with this! a bit revision to get it automatically move executable to quarantine directory. And interestingly, a exe file is FOUND not an executable!! but its all fine.
#!/bin/bash
SAMBAPATH=/exports/samba
LIST=`ls $SAMBAPATH`
LOOKFOR="x-dosexec"
EXE=/tmp/exelist.log
cd $SAMBAPATH
for i in $LIST; do
if (file -ib $i | grep $LOOKFOR > /dev/null 2>&1>/dev/null); then
echo $i >> $EXE
fi
done
cat $EXE | while read index; do mv $index /tmp/quarantine/;done;
rm $EXE