I have been writing a lot of shell scripts lately as part of the C/Unix class that I'm taking at Harvard Extension. My familiarity with how the Unix shell and the underlying system works has grown exponentially. When I came across a problem earlier today, I subconsciously turned the problem into a shell script without even thinking about it!
The problem: "How can I check to make sure my program is running every 30 minutes and restart it if it's not?"
# If myscript isn't running, restart it ONLINE=`ps aux | grep -c myscript` # 2 because grep myscript also finds 'grep myscript' if [ $ONLINE -ne "2" ]; then $MYSCRIPT_PATH/restart_service.sh fi
I'm sure there are many better ways to solve this problem, but the fact that I instantly translated the problem into shell scripting code (and that it worked as expected on my first try) astonished me. I can see how good programmers who write in a particular language, and know the in's and out's the like the back of their hand can turn problems into code seamlessly (or know exactly where to look to find answers if they're unsure).
It's really amazing how easily you can solve simple problems when you have a deeper understanding of how the system works.
That's all. I just wanted to share my excitement. 🙂