crontab Help

New to Debian (Or Linux in general)? Ask your questions here!

crontab Help

Postby Tropic » 2017-11-30 06:12

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
Tropic
 
Posts: 3
Joined: 2017-11-30 06:02

Re: crontab Help

Postby Segfault » 2017-11-30 13:56

Does not work like this. First you show what you have done and where you got stuck. There are no free handouts here.
Segfault
 
Posts: 557
Joined: 2005-09-24 12:24

Re: crontab Help

Postby GarryRicketson » 2017-11-30 14:25

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/questions/56189/appending-timestamp-stamp-along-with-log-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.
"What we expect you have already Done"

Before doing anything, read the Debian documentation:
Debian Documentation
How to ask the smart way
Debian Foro Español
======================
For the Birds
User avatar
GarryRicketson
 
Posts: 4470
Joined: 2015-01-20 22:16
Location: Durango, Mexico

Re: crontab Help

Postby Segfault » 2017-11-30 17:06

I see I was wrong. Some are giving handouts here. Is it good for our OP? I doubt it. None of my business, really.
Segfault
 
Posts: 557
Joined: 2005-09-24 12:24

Re: crontab Help

Postby GarryRicketson » 2017-11-30 17:52

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 $$$,
"What we expect you have already Done"

Before doing anything, read the Debian documentation:
Debian Documentation
How to ask the smart way
Debian Foro Español
======================
For the Birds
User avatar
GarryRicketson
 
Posts: 4470
Joined: 2015-01-20 22:16
Location: Durango, Mexico

Re: crontab Help

Postby Tropic » 2017-11-30 20:23

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 :)
Tropic
 
Posts: 3
Joined: 2017-11-30 06:02


Return to Beginners Questions

Who is online

Users browsing this forum: Capitain_Jack and 9 guests

fashionable