I'm trying to create a shell script that:
copies a file from my log directory to a separate directory for analysis.
Gunzips that file and looks for a text pattern
Outputs that pattern to a file for further analysis
deletes said file
I'm trying to do this in stages. So far I haven't been able to get off the ground. SIGH...
I pulled this example from here and started amending it:
#!/bin/bash
FILES= `ls /opt/dir1/scripts/access_*.gz`
for i in $FILES
do
cp $i /tmp/apache
gunzip $i | grep -i 'Mozilla' >> output.txt
done
Every time I do this, I get a permission denied message like this:
./test1.sh: line 7: /opt/dir1/scripts/access_log.1.gz: Permission denied
even though I'm running this script as root and if I do these commands manually, I have no problem. Any ideas?
Thanks