solo2500
Posts: 123
Joined: Sat Jul 09, 2016 12:38 am

Time stamp to log file?

Sat Sep 03, 2016 6:44 pm

I would like to add a time stamp to a ftp.log file every time I send a file. I'm using a cron job to send the file every 5 minutes using the following:

1,6,11,16,21,26,31,36,41,46,51,56 * * * * /home/pi/imagesend_scr1 >> /home/pi/ftp.log 2>&1

1,6,11,16,21,26,31,36,41,46,51,56 * * * * /home/pi/imagesend_scr1 >> /dev/null 2>&1

Is there a simple (elegant?) way to do this?

THANKS ALL!!!
I'm a total novice, non-programer (...basically a hack.)

pcmanbob
Posts: 9467
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Time stamp to log file?

Sat Sep 03, 2016 6:56 pm

you can replace

1,6,11,16,21,26,31,36,41,46,51,56 * * * *

with

*/5 * * * *

and it will run
2016-09-03 19:00:00 UTC
2016-09-03 19:05:00 UTC
2016-09-03 19:10:00 UTC
2016-09-03 19:15:00 UTC
2016-09-03 19:20:00 UTC
if that is what you are talking about by more elegant
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

solo2500
Posts: 123
Joined: Sat Jul 09, 2016 12:38 am

Re: Time stamp to log file?

Sat Sep 03, 2016 7:41 pm

Yes.. quite a bit more elegant... thanks.
But I would actually like to add a time stamp to the output of : imagesend_scr1
pcmanbob wrote:you can replace

1,6,11,16,21,26,31,36,41,46,51,56 * * * *

with

*/5 * * * *

and it will run
2016-09-03 19:00:00 UTC
2016-09-03 19:05:00 UTC
2016-09-03 19:10:00 UTC
2016-09-03 19:15:00 UTC
2016-09-03 19:20:00 UTC
if that is what you are talking about by more elegant
I'm a total novice, non-programer (...basically a hack.)

User avatar
DougieLawson
Posts: 39124
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Time stamp to log file?

Sat Sep 03, 2016 7:53 pm

Does it have to be on the x1 & x6 minutes? Or can it run on x5 and x0 minutes?

You could use Bob's option and include a sleep(60) in your script.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

solo2500
Posts: 123
Joined: Sat Jul 09, 2016 12:38 am

Re: Time stamp to log file?

Sat Sep 03, 2016 8:04 pm

I think you guys may be missing the point (or more likely I'm doing a poor job of articulating the question... ) The output of the ftp script I'm running has no time information... I'd like to know what time the connection information occurred. I would like to insert a time stamp into the log file whenever a log message is generated.

Thanks again!!!
DougieLawson wrote:Does it have to be on the x1 & x6 minutes? Or can it run on x5 and x0 minutes?

You could use Bob's option and include a sleep(60) in your script.
I'm a total novice, non-programer (...basically a hack.)

pcmanbob
Posts: 9467
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Time stamp to log file?

Sat Sep 03, 2016 8:22 pm

if you wanted to output a time stamp to your log file you could do this.

you could add this to your script.

Code: Select all

current_time=$(date "+%H:%M:%S")
echo "Executed at $current_time" >>/home/pi/ftp.log
you could even create a start and finish time if you wished.

Code: Select all

start_time=$(date "+%H:%M:%S")

your existing script goes in here

end_time=$(date "+%H:%M:%S")
echo "Started at $start_time" >>/home/pi/ftp.log
echo "Ended at $end_time" >>/home/pi/ftp.log
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

solo2500
Posts: 123
Joined: Sat Jul 09, 2016 12:38 am

Re: Time stamp to log file?

Sat Sep 03, 2016 10:05 pm

Works perfect!!!
THANKS!!!
I'm a total novice, non-programer (...basically a hack.)

Return to “Beginners”