Dhunt90
Dhunt90

Reputation: 81

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.

Upvotes: 1

Views: 723

Answers (2)

Red Cricket
Red Cricket

Reputation: 10460

  • Extract Today's data from /var/log/secure file

You could do this ...

grep "^Feb 24" /var/log/secure
  • Check to see if I have a directory called 'mylogs' and If I don't - then create one

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>

Upvotes: 2

Related Questions