I am using SUSE Linux Enterprise Server 11 (x86_64)
I need to find a folders oldest file and print it out in unixtime. I did get the job done with this one liner: find $1 -maxdepth 1 -type f | xargs -i stat -c "%Y" '{}' | sort | head -n 1
(the $1 is for Zabbix)
But when the folder becomes empty the value also seem to be empty and my monitoring software, Zabbix, cant handle empty values so I need it to, for example print out number 0 if the folder is empty.
Okay so next I composed this beautiful script but as you all can see it's pretty shait. So could anyone help me out with this?
FYI. I started messing around with linux two days ago so please bear with me :P
#!/bin/bash
export fileage
fileage=$(find -maxdepth 1 -type f | xargs -i stat -c "%Y" '{}' | sort | head -n 1)
if [ $? -eq 0 ]
then
echo "0"
else
echo "fileage"
fi