Networking

Unix and Linux network configuration. Multiple network interfaces. Bridged NICs. High-availability network configurations.

Applications

Reviews of latest Unix and Linux software. Helpful tips for application support admins. Automating application support.

Data

Disk partitioning, filesystems, directories, and files. Volume management, logical volumes, HA filesystems. Backups and disaster recovery.

Monitoring

Distributed server monitoring. Server performance and capacity planning. Monitoring applications, network status and user activity.

Commands & Shells

Cool Unix shell commands and options. Command-line tools and application. Things every Unix sysadmin needs to know.

Home » Commands & Shells

Better ‘date’ Functionality in Solaris

Submitted by on June 28, 2016 – 8:53 am

The Solaris date command does not have many of the useful features of its GNU equivalent. A workaround is to use Tcl. This requires tclsh to be installed (which tclsh). You can implement this workaround as a function:

tcldate() {
    d=${1:-now}   # input date string
    f=${2:-%c}    # output date format
    echo "puts [clock format [clock scan {$d}] -format {$f}]" | tclsh
}

Or as a script (ln -s /var/adm/bin/tcldate.sh /usr/bin/tcldate):
#!/bin/bash
tcldate() {
    d=${1:-now}   # input date string
    f=${2:-%c}    # output date format
    echo "puts [clock format [clock scan {$d}] -format {$f}]" | tclsh
}
tcldate "$1" "$2"

Some examples:
# date ; tcldate "`date`+1month+12days+17hours+12minutes+30seconds" "%Y-%m-%d %H:%M:%S"
Tuesday, June 28, 2016 08:52:39 AM EDT
2016-08-10 02:05:09

 

Print Friendly, PDF & Email

Leave a Reply