So, I have a bash script that should pipe the output of ifconfig to a text file on the hour, every hour. As many people seem to have encountered, this script does not funct
The ip.sh script is supposed to zap the ip.txt file every time it is run; it is then up to the ifconfig program to repopulate it. So, your problem is that ifconfig isn't doing that.
The usual problem when running things from cron is environment. Note that when cron runs a command, the profile is not used.
In this case, I'd lay odds that the PATH setting under cron doesn't include the directory where ifconfig lives (so /sbin is not on PATH). Obvious workarounds:
/sbin/ifconfig ...export PATH=$PATH:/sbin; ifconfig ...I think simply running a script from the crontab file is usually the best way to do business. Without changing the crontab settings, you can add debug code, change the environment settings, and otherwise tinker to your heart's content. Fiddling with complex command lines in the crontab file is liable to run into trouble, sooner or later, on some system or other. So I think your system is sensible - I use a somewhat more complex system in my own cron-run scripts, but there is a lot of commonality. The key point is that the crontab entry is simple and the script that's run is where the complexity is hidden.