Basic Shell Scripting in BASH
I'm in my first semester of BASH Scripting and I am having some difficulty. I've taken other programming courses like C++ or Java but the syntax of Bash is killing me. I'd love some advice on this problem. I need to do the following:
I just need help with the syntax portion of the script.
Thanks - I'd love any websites helping out in BASH as well.
You could do this ...
grep "^Feb 24" /var/log/secure
You can do this ...
test -d mylogs || mkdir mylogs
Check to see if you already have a file matching the current day, month and hour in the 'mylogs' directory. (Assuming file names are of the format DDMMHH)
test -e mylogs/`date +%d%m%H` && echo "I already have a file"
If you do, echo to the screen “File exists, nothing written to my log”, and exit. If it doesn't exist then write today's data from /var/log/secure to your 'mylog-month-day-hour' file. Example (February, 4th at 2pm) output: mylog-02-04-14
Eh you should get the idea by now. You can tackle this one now I think ;) A helpful command to know is man -k <keyword>
First read some bash basics. Then, there are links describing your particular problem.
上一篇: cp命令的怪异行为
下一篇: BASH中的基本shell脚本