I’m using a mini shell script in order to ‘tail’ (in real time) a bunch of log files.
#!/bin/sh
oldGLOBIGNORE=$GLOBIGNORE
export GLOBIGNORE='foo-bar.log'
sudo -E tail -f -n0 /var/log/*.log
GLOBIGNORE=$oldGLOBIGNORE
As you can see, I want to log all files except the one named foo-bar.log.
the -E option of sudo should allow me to keep the GLOBIGNORE variable but it looks like it does not work.
I’m testing on Ubuntu 10.04, bash 4.1.5.
Any clue ?
Firstly —
GLOBIGNORErelates to the full filepath resulting from filename-expansion, not just the last part. So you actually want to writeGLOBIGNORE='/var/log/foo-bar.log'.Secondly — you don’t actually need to export
GLOBIGNOREinto the environment and add-E, because the/var/log/*.loggets expanded by Bash before it even invokessudo.Thirdly — your approach to saving the old value of
GLOBIGNOREand restoring it afterward is less than ideal, because the behavior whenGLOBIGNOREis unset is different from its behavior when it’s set-but-empty, and your script can never restore it to being unset. Fortunately, the script doesn’t need to restore it (since it’s not as though a script’s variables could continue to have effect after the script returns), so you can just remove that stuff.All told, you can write: