Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

crontab Help

New to Debian (Or Linux in general)? Ask your questions here!
Post Reply
Message
Author
Tropic
Posts: 2
Joined: 2017-11-30 06:02

crontab Help

#1 Post by Tropic »

Hi,
I was just wondering if anyone could help i've to use the date and who command to create a single crontab job that appends a timestamp and a list of logged in users to a log file /root/hawk.
I'm not sure how to do this.

Any help would be gratefully appreciated.

Thanks

Segfault
Posts: 993
Joined: 2005-09-24 12:24
Has thanked: 5 times
Been thanked: 17 times

Re: crontab Help

#2 Post by Segfault »

Does not work like this. First you show what you have done and where you got stuck. There are no free handouts here.

User avatar
GarryRicketson
Posts: 5644
Joined: 2015-01-20 22:16
Location: Durango, Mexico

Re: crontab Help

#3 Post by GarryRicketson »

This seems to yield some results :
use the date and who command to create a single crontab job that appends a timestamp and a list of logged in users to a log file

In fact , the first hit is almost identical to the question posted here :
https://unix.stackexchange.com/question ... file-lines

The 'last' command includes a date/time stamp,

Code: Select all

man last

Code: Select all

$ last
garry     ttyC0                             Thu Nov 30 08:05   still logged in
reboot    ~                                 Thu Nov 30 08:03
shutdown  ~                                 Wed Nov 29 23:52
garry     ttyC0                             Wed Nov 29 08:00 - shutdown  (15:51)
------ snip ---------
garry     ttyC0                             Sun Nov 19 03:58 - shutdown  (16:17)
reboot    ~                                 Sun Nov 19 03:57
shutdown  ~                                 Sat Nov 18 19:49
But if you must use the 'who' command, well :

Code: Select all

$ who
garry    ttyC0    Nov 30 08:05  
So you use :

Code: Select all

man crontab
================

Code: Select all

man date
==============

Code: Select all

man who
==============

Code: Select all

man last
Combined with read some of the results in a search, .... you should be able to find something.

Segfault
Posts: 993
Joined: 2005-09-24 12:24
Has thanked: 5 times
Been thanked: 17 times

Re: crontab Help

#4 Post by Segfault »

I see I was wrong. Some are giving handouts here. Is it good for our OP? I doubt it. None of my business, really.

User avatar
GarryRicketson
Posts: 5644
Joined: 2015-01-20 22:16
Location: Durango, Mexico

Re: crontab Help

#5 Post by GarryRicketson »

No, you are not wrong, it is good to try to get the OP to do a little bit of searches, Was I wrong to suggest using the keywords ? " use the date and who command to create a single crontab job that appends a timestamp and a list of logged in users to a log file", and it was kind of a surprise to see the first hit was another post with almost the same question, ... the OP still needs to
try to take the information and use it to suit their need.
Maybe it is me that was wrong ? :(

To be honest, if it was me, I wouldn't even bother with using crontab and the 'who' command,... I use the 'last' command, and it shows all the users that have logged in and the date, and if one wanted they could have it print the output
to any path they choose:
example:

Code: Select all

last > /home/garry/last-log.txt
Or, using 'who' :

Code: Select all

who > /home/garry/loggedin.txt 
That could be put into a crontab script,.... all the OP needs now is to just
read the manuals a little, and figure out how to put the pieces together into
something they can use.
====
Well,, maybe on this :
There are no free handouts here.
No body charges any one for the advise, or comments they make, in that
sense it is all "free handouts", nobody pays any body, we are all volunteers,
those that choose to give a answer, advice, or suggestion are free to do so,
like wise, those that don't want to give any suggestion or ideas,or answer are free to not do so. But then again , maybe I am wrong, it certainly would not be the first time I am wrong,....

Someone else might even be able to simply post a script that does exactly what the OP s looking for, but I don't think that would help the OP learn anything, beyond copy/paste a script, but in any event, if some one did that,
they are free to do so, as long as they don't try to charge the OP a fee $$$,

Tropic
Posts: 2
Joined: 2017-11-30 06:02

Re: crontab Help

#6 Post by Tropic »

Thanks for taking the time to reply and offer some help, it is much appreciated.
I did search for information but wasn't sure if what I found was what I needed, but the information above is helpful.

Thanks again :)

Post Reply