In Linux,
"echo %date% %time% %COMPUTERNAME%"
returns
%date% %time% %COMPUTERNAME%
not
Fri 09/24/2010 10:46:25.42 WXP2010043001
as Windows does. I need to be able to do this for the logs I'm setting up.
Use the date command with a format like this:
date +"%m/%d/%Y %H:%M:%S $HOSTNAME"
To get hundredths of seconds, you may need to do some text processing like this:
DATE=date +'%m/%d/%Y %H:%M:%S.%N'
DATE=${DATE%???????}
DATE="$DATE $HOSTNAME"
This is because date offers seconds, nanoseconds, and nothing in between!
You can do:
dt=$(date)
echo $dt $HOSTNAME
echo $(date '+%Y %b %d %H:%M') Your output $HOSTNAME
Outputs:
2013 Nov 01 09:11 Your output PEGASUS-SYDNEY-CL2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With