LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 10-08-2012, 01:48 PM   #1
jayfurrie
LQ Newbie
 
Registered: Oct 2012
Posts: 5

Rep: Reputation: Disabled
parsing a file + cron email job


Hey guys,

I've got an assignment i'm bummed on. It involves parsing a certain log file, appending new records on that log file to an email that crontab sends out at midnight everynight to three people.

This log files keeps track of when someone su's to root, but I'm not quite sure where this file is. Also, can someone give me or point me to a website with a good example crontab explaination or something that shows me how crontab works? I've never used it before =/

Oh, and I also don't know how to parse a file for new entries, and then copying and pasting those entries into a new document/email.

Any help would be appreciated! I'm really suck =[

edit: Also, a few other things...
1. no email should be sent out if there haven't been su - root 's in the past 24 hours.
2. logs should be kept for 4 weeks, although emails should not include duplicates.
3. A direct quote from my assignment - "As root you will not run this from an installed crontab but
instead you will have it run in the typical way that root does." I haven't the slightest inkling what this means -____-

Last edited by jayfurrie; 10-08-2012 at 01:51 PM.
 
Old 10-08-2012, 06:38 PM   #2
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,301

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
I'm going to give you a few things to read, which will help you do this assignment
http://rute.2038bug.com/index.html.gz
http://www.adminschoice.com/crontab-quick-reference

The log file is probably /var/log/secure, but your lecturer should have told you where it is or at least what its called.
See also /var/log/messages.
You can use the find cmd http://linux.die.net/man/1/find to find a file on a system.

You're going to need to learn bash (shell scripting lang) so
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/

I agree that last remark is meaningless as stated; I assume(!) it was in the context of the lecture.
He may mean that as well as the system crontabs, root (like all users) also has his own personal crontab.
Try looking under /var/spool/cron and/or see the crontab link I gave you.
 
1 members found this post helpful.
Old 10-10-2012, 01:29 AM   #3
jayfurrie
LQ Newbie
 
Registered: Oct 2012
Posts: 5

Original Poster
Rep: Reputation: Disabled
Thanks Chris!

Heres an update on what I've done:
I've done "crontab -e" to edit the crontab list, what I have right now is "05 00 * * * ./foo1.sh"
I'm thinking I'll be running some script at 12:05am every day, regardless of date month or year or anything like that.
I learned how to find my home directory (lol i had no idea how to figure that out before) with echo $HOME,
I went to my home directory and did "touch foo1.sh"

Here's something I'd like clarified... I read that crontab sends out an email to root everytime a job executes properly. Since I need to send an email to my instructor smauney, me jhong23, and root, would the other two emails to smauney and jhong23 be sent out via my bash script? Also, the confirmation email being sent by crontab isn't even the email that's supposed to be sent actually, the email that's supposed to be sent should have a list of times someone su-ed root - which I'm guessing my bash script should help me do. Could you confirm this?

Sorry for all these questions, but I really appreciate any help!
 
Old 10-10-2012, 02:30 AM   #4
jayfurrie
LQ Newbie
 
Registered: Oct 2012
Posts: 5

Original Poster
Rep: Reputation: Disabled
So, I've taken a look at the bash links you gave me Chris, and I'm having a bit of a problem narrowing down which sections I need to read.
Here's some pseudocode (I've taken C), if you or someone else could kindly help me figure out the exact syntax that would be great!
What I know so far is that there are no headers in bash, or formal declaration of variables or their types. some nuances here and there, and the end of the code isn't a return 0 or end or something.

#no headers, so we're skipping the .h's

#skipping the int main() as well

#checks to see if anyone has su-ed root
y = grep root <su root log file>;

for (y==1)
#yes, someone has su-ed to root
mail -s "users su-ed to root" user1@hostname1, user2@hostname2, user3@hostname3;
#no, noone has su-ed to root OR just finished the yes part
end (whatever end is in bash)
 
Old 10-11-2012, 05:19 AM   #5
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,301

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
Well, you should have noticed that (ideally) a shell script starts by specifying which shell (there are several) to use. The default in Linux is normal bash thus
Code:
#!/bin/bash
This must be at the start of the very first line (no blanks before)
To see what the parser is doing, make the next line
Code:
set -xv
You should really try out some of the code in those links (inc the Rute tutorial) and forget what you know about C.
Don't try to do it all in one go; get some basic simple stuff working first.

When you've done that, have a go (in stages) at the assignment and come back when you've got some code to show.

Incidentally, cron does not login to your home dir, so
Code:
05 00 * * * ./foo1.sh
won't work, you need to specify the complete path eg
Code:
05 00 * * * /home/username/foo1.sh

Last edited by chrism01; 10-11-2012 at 05:49 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cron job parsing error clcbluemont Linux - Software 9 12-19-2009 09:05 AM
Creating a cron job to email me a txt file/format? NewShockerGuy Linux - General 7 05-16-2008 09:23 AM
Blank email on Cron job Taleya Linux - Newbie 3 12-19-2007 07:52 PM
cron job email results... ryedunn Linux - General 7 01-26-2005 10:27 PM
cron job that email a text file paynsr Linux - Newbie 1 03-29-2004 01:36 PM


All times are GMT -5. The time now is 02:14 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration