Thank you mglae and chewitt. I tried both the scripts. The first script didn't work and i saw errors in the journal. Then i saw the second script here and overwrote the first script. I'm getting the same errors like in first script.
Code
/bin/sh: can't open '/storage/.config/shutdown.sh': No such file or directory
......
/storage/.config/autostop.sh: line 7: udiskctl: not found
I'm uploading the entire log here i took using journalctl -b -1
I think Kodi unmounts the devices using ntfs-3g or another service even before the shutdoown script is run. So when the script does run it is throwing errors.
One thing I noticed is that the disks don't make that dreaded noise after putting the shutdown script. They don't power off but the hard disk heads are already parked before they shut down so no noise now.