Hi the following script let sthe user know whenevr any file is changed inserted or deleted in file system.
but i am getting following error while running bash script
## LINUX SYSTEM FILE ARCHIVE NOTIFY ##
if [ ! $# -eq 2 ] ; then echo "Usage '$0 folder waitseconds' " ; exit 1; fi
if [ ! -d $1 ] ; then echo "Folder name is false!!" ; exit 1 ;fi
cd /usr/local/bin ; clear ; tmp='tmppx' ; tmpp="${tmp}x"
f="find '$1' -not \( -name $tmp -o -name $tmpp \) -exec stat -c '%s %n' {} \;"
eval $f >$tmp ; echo -e "Please wait.. Preparing File Lists!!" ; sleep $2 || exit 1 && echo "Lists OK!!"
eval $f >$tmpp ; lcltmp=lcltmp;lcltmpp="${lcltmp}x";lcltmppp="${lcltmpp}x"
cretdif() {
diff $tmp $tmpp|sed -n '/^[><]/p'|sort -k3,3>$lcltmp
}
chksz() {
dtecs=$(awk '{print $3}' $lcltmp|uniq -d)
}
rmvdupf() {
for dup in $dtecs ; do sed 's|.*'$dup'$||;/^$/d' $lcltmp>$lcltmpp && mv $lcltmpp $lcltmp -f;done
}
fnddupf() {
>$lcltmppp
for dup in $(echo "$dtecs"|sed 's|/|\\&|g') ; do
sed -n '/.*'$dup'$/p' $lcltmp>>$lcltmppp;done
}
chkfls() {
newrem=$(sed -n '/^['$1']/p' $lcltmp)
}
fix() {
sed -n 'N;s/[^ ]* \([^ ]*\) \([^ ]*\)\n\([^ ]*\) \([^ ]*\) \2$/\2 \1 \4 \3/p' $lcltmppp|
awk 'BEGIN {printf "%20s" "%30s\n" "%15s" "%10s\n" ,"File Name(s)","Difference (Bytes)","-----------------------------"," ------------------------"};
{if($4==">")printf "%20s" "%10c" "%d" "%2s", $1 ,"+",$3-$2, " bytes";
else printf "%20s" "%10d" "%2s\n", $1, $2-$3, " bytes"};
END { printf "\n%31s\n%19s\n\n" ,"[End of summary list]","#########################################################" }'
}
cretdif;if [ ! -s $lcltmp ] ; then echo -e "No any changes!!..";exit 0;fi
chksz;if [ ! "$dtecs" = "" ] ; then printf "%s\n%34s\n%30s\n" "#########################################################" "[Detected change of size]" "-----------------";fnddupf;fix;fi;rmvdupf
chkfls '>';if [ ! "$newrem" = "" ] ; then
printf "\n%s\n%34s%+61s\n%+30s%70s\n" "#########################################################" "[Detected new created files]" "[Type]" "---------------------" "----------------"
echo "$newrem"|awk '{if (!system("test -d " $3) )printf "%-60s" "%+36s\n",$0,"directory"; else printf "%-60s" "%+34s\n" ,$0,"file"};
END { printf "\n%31s\n%19s\n\n" ," [End of summary list]","#########################################################" }';fi
chkfls '<';if [ ! "$newrem" = "" ] ; then
printf "\n%s\n%34s%+61s\n%+30s%70s\n" "#########################################################" "[Detected removed files]" "[Type]" "-----------------" "----------------"
echo "$newrem"|awk '{if (!system("test -d " $3) )printf "%-60s" "%+36s\n",$0,"directory"; else printf "%-60s" "%+34s\n" ,$0,"file"};
END { printf "\n%31s\n%19s\n\n" ,"[End of summary list]","#########################################################"}';fi
ERROR:
<html>
<body>
'/chkmodifsearch.sh: line 8: syntax error near unexpected token `{
'/chkmodifsearch.sh: line 8: `cretdif() {
</body>
</html>
PHP CODE;
i am trying to call the bash script from php by using the following code.
<html>
<body>
<?php
$i=0;
$output = shell_exec \("./chkmodifsearch.sh"\);
while \($i < count\($output\)\)
\{
echo "The Search Data is " . $output[$i] . "<br>";
$i\+\+;
\}
?>
Kindly assist me why the unexpected token `{ error is being generated. If sed awk '' and `` thing needs to be done please do it in the bash script
</body>
</html>