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.
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 hundreds 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!
As a complement: percentage character is not used to reference variables on any Linux shell. You should use the dollar sign for this.
You should probably read an introduction to Bash (here)
In Linux, there is the date command. If you don't like the default format, it can be modified. See the manpage of date
For hostname, you can use hostname command, or $HOSTNAME environment variable, if it is set.
With system name, it is more complicated. You can use uname -a, sometimes it contains the OS name. Some distributions also have lsb-release, but not all of them.
Several people have provided answers based on date
, but your question requires the short day name (although my UK Win 7 installation doesn't provide this with the ECHO command you specified), which no one has (so far) addressed.
To get this, you will probably want to include %a
in the format string:
date "+%a %m/%d/%Y %H:%M:%S $HOSTNAME"