How to check the timestamp using script

I need to check my timestamp after "seconds since 1970-01-01 00:00:00 UTC" and print it to this csv file.

What's wrong in this code?

#!bin/bash
echo %computername%, timestamp=$( date +%T ) >> "system_monitor.csv" 

1 Answer

From man date:

%s seconds since 1970-01-01 00:00:00 UTC

So you want date +%s, not date +%T.

And if by %computername% you mean the hostname, use the $HOSTNAME variable or the hostname command. So, something like:

#!bin/bash
echo "$HOSTNAME, timestamp=$( date +%s )" >> "system_monitor.csv" 

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like