I have the script below running as a deamon. It checks for new .gz files in a upload file. moves it to the correct location en gzip's it.
When i run the script (as root (bad me)) by hand it works. when the deamon runs it gives the error
Dec 22 16:56:06 server watchftp.script[131856]: gzip: /var/www/html/config/MER2-SRX.conf.gz: unexpected end of file
I don't see where the problem is. anyone else??
Script code:
#!/bin/bash
savedir='/var/www/html/config/'
inotifywait -m /srv/ftp/upload -e create -e moved_to |
while read dir action file; do
echo "The file '$file' appeared in directory '$dir' via '$action'"
#set correct permissions
chown root:root $dir$file
chmod 755 $dir$file
#create new filename and subdirectory name for save location
newfilename=$( echo -n $file | cut -d '_' -f 1)
parkdir=$( echo -n $newfilename | cut -d '-' -f 1)
mv $dir$file $savedir$newfilename.conf.gz
#check if subdirectory exist otherwise create it
if [[ ! -d $savedir$parkdir ]]; then
echo "create directory $savedir$parkdir"
mkdir $savedir$parkdir
fi
gunzip -dc $savedir$newfilename.conf.gz > $savedir$parkdir/$newfilename.conf
done