I have been using bash scripts for just that..
Bash is one of the weirdest languages i have had to learn...stuff isn't that straight forward. I hade to google this stuff up
If [ conditional expression1 ] then statement1 statement2 . elif [ conditional expression2 ] then statement3 statement4 . . . else statement5 fiI wont take all the credit, I got the info from HERE