stat(1) returns outdated info
Hi,
I've written a little script that gives me a message upon login in case of pending commit in my local git repository.
It worked OK until I upgraded to 14.04.1: Then, it started to show false positive.
In the end, I tracked the problem to be related with stat(1) returning outdated information (See hereunder for more details).
Does anyone has a clue of why stat(1) returns outdated info?
Best regards,
Cyrille
=======
Technical details:
==============
The script is placed in the /etc/update-
if [ -d /etc/.git ];then
cd /etc
diff=$(sudo git status --porcelain);
if [ -n "$diff" ];then
echo
echo '!!!!!!
echo
echo 'WARNING: There are uncommited changes in the /etc directory!'
echo
echo ' Please run "cd /etc;git status" to figure out what is going on.'
echo
echo '!!!!!!
fi
fi
Now, as I said, it started to return false positive after the upgrade to Ubuntu 14.04.1. For example, yesterday, I've created a file /etc/test during a few hours and then deleted it and today I've had a false positive against this file (It's quite easily reproductible).
Hopefully, I'd changed my script to give me more information:
if [ -d /etc/.git ];then
cd /etc
diff=$(sudo git status --porcelain);
if [ -n "$diff" ];then
echo
echo '!!!!!!
echo
echo 'WARNING: There are uncommited changes in the /etc directory!'
echo
echo ' Please run "cd /etc;git status" to figure out what is going on.'
echo "$diff"
f=$(echo $diff | cut -f 2 -d " " -)
git ls-files --debug $f
stat --format "%n %Y %Z %s" $f
echo
echo '!!!!!!
fi
fi
And, the result was this:
login as: support
support@xxx's password:
Welcome to Ubuntu 14.04.1 LTS (GNU/Linux 3.13.0-37-generic x86_64)
* Documentation: https:/
!!!!!!!
WARNING: There are uncommited changes in the /etc directory!
Please run "cd /etc;git status" to figure out what is going on.
?? test
test 1414588482 1414588482 0
!!!!!!!
System information as of Wed Oct 29 14:54:19 CET 2014
System load: 0.28 Processes: 153
Usage of /: 4.6% of 45.71GB Users logged in: 1
Memory usage: 1% IP address for p1p1: a.b.c.d
Swap usage: 0%
Graph this data and manage this system at:
https:/
16 packages can be updated.
16 updates are security updates.
Last login: Wed Oct 29 14:54:19 2014 from 2001::
support@xxx:~$ stat /etc/test
stat: cannot stat ‘/etc/test’: No such file or directory
support@xxx:~$
See how stat(1) returns outdated information during the motd?
Question information
- Language:
- English Edit question
- Status:
- Solved
- For:
- Ubuntu Edit question
- Assignee:
- No assignee Edit question
- Solved by:
- Manfred Hampl
- Solved:
- Last query:
- Last reply: