How to get the version of Zimbra I am using in a Zimbra server? In Zimbra, to get the version of Zimbra you are using, you can call zmcontrol -v: $ zmcontrol -v Release 7.2.6_GA_2926.F13_64_20131203115902 F13_64 FOSS edition.
Tag: Tutorial
How to disable DHCP in dnsmasq on Linux?
Posted onHow to disable the DHCP service in dnsmasq on Linux? That is, to leave only dnsmasq’s DNS service. The `/etc/dnsmasq.conf` file may have lines that enable DHCP service of dnsmasq. By default, the DHCP is disabled in dnsmasq (check one example dnsmasq.conf file). To disable DHCP service in dnsmasq, in `/etc/dnsmasq.conf`, remove or disable the
Read more
How to delete or get the number in the tail from a string in shell script?
Posted onHow to delete or get the number in the tail from a string in shell script (bash script)? Okay to call other tools. For example, from “/dev/sda8”, I want to get “/dev/sda” and “8” separately. This can be achieved by using sed as follows. To get the string after deleting the tailing numbers, we can
Read more
How to split a string by string in PHP?
Posted onHow to split a string by string in PHP? For example, “a string separated by space” => [“a”, “string”, “separated”, “by”, “space”] and “a,string,separated,by,comma” => [“a”, “string”, “separated”, “by”, “comma”] The commonly used `explode()` is not enough here because multiple delimiters should be consider as one (such as ” “, 3 spaces together, is consider
Read more
How to split a string by string in Bash?
Posted onHow to split a string by string in Bash? For example, “a string separated by space” => [“a”, “string”, “separated”, “by”, “space”] and “a,string,separated,by,comma” => [“a”, “string”, “separated”, “by”, “comma”] You can convert a string to an array using the grammar like inarr=(${a}) If the delimiter is not space and delimiter is a single character
Read more
Getting Hostname in C Programs in Linux
Posted onIn C, how to get the hostname of the node? In C, you may use the gethostname function. #include <unistd.h> int gethostname(char *name, size_t namelen); The gethostname() function shall return the standard host name for the current machine. The namelen argument shall specify the size of the array pointed to by the name argument. The
Read more
How to get the hostname of the node in C++?
Posted onIn C++, how to get the hostname of the node? In C++, the C way works too. However, with Boost, you can use the boost::asio::ip::host_name() function to get the hostname as a std::string: namespace boost { namespace asio { namespace ip { /// Get the current host name. BOOST_ASIO_DECL std::string host_name(); … More at http://www.boost.org/doc/libs/1_63_0/boost/asio/ip/host_name.hpp
Read more
How to get the hostname of the node in Go?
Posted onIn Go lang, how to get the hostname of the node? In Go, you can use the os.Hostname() function to get the hostname of the node. func Hostname() (name string, err error) Hostname returns the host name reported by the kernel. One example is as follows. The main.go source code: package main import ( “fmt”
Read more
How to convert epoch timestamp to human readable date format in Bash?
Posted onIn Bash, how to convert an epoch timestamp to a human readable date format? In Bash, you can use the date command’s -d option: date -d @<your epoch> Here @ specifies the epoch timestamp. One example: $ date -d @1490157520.05 Wed Mar 22 12:38:40 HKT 2017
Getting Hostname in Bash in Linux in 3 Ways
Posted onGetting the hostname of the node running a program can be useful in various scenarios, such as creating logs with the hostname, identifying which node a script is running on, or configuring a distributed system with different nodes. In Bash, there are several ways to retrieve the hostname of the machine, as mentioned in the
Read more
How to get the hostname of the node in Python?
Posted onIn Python, how to get the hostname of the node? In Python, you can get the hostname by the socket.gethostname() library function in the socket module: import socket hostname = socket.gethostname() Example: $ python Python 2.7.5 (default, Nov 6 2016, 00:28:07) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux2 Type “help”, “copyright”, “credits” or “license”
Read more
Getting Epoch Timestamp in C
Posted onIn C, how to get the epoch timestamp, the number of seconds passed since the epoch? In C, from man 7 time: UNIX systems represent time in seconds since the Epoch, 1970-01-01 00:00:00 +0000 (UTC). A program can determine the calendar time using gettimeofday(2), which returns time (in seconds and microseconds) that have elapsed since
Read more
How to convert epoch timestamp to human readable date format in Python?
Posted onHow to convert an epoch timestamp to a human readable date format? In Python: import time time.strftime(“%a, %d %b %Y %H:%M:%S %Z”, time.localtime(epoch)) One example: $ python Python 2.7.5 (default, Nov 6 2016, 00:28:07) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux2 Type “help”, “copyright”, “credits” or “license” for more information. >>> import time >>>
Read more
How to get the epoch timestamp in Java?
Posted onIn Java, how to get the epoch timestamp, the number of seconds passed since the epoch? In Java, you can get the current time in milliseconds and then calculate the epoch time: long ts = System.currentTimeMillis()/1000; Example: $ wget –quiet https://github.com/albertlatacz/java-repl/releases/download/428/javarepl-428.jar -O /tmp/javarepo-428.jar && java -jar /tmp/javarepo-428.jar Welcome to JavaREPL version 428 (Java HotSpot(TM) 64-Bit
Read more
How to get the epoch timestamp in Go lang?
Posted onIn Go lang, how to get the epoch timestamp, the number of seconds passed since the epoch? In Go, you can use the time.Now() func to get current time and its Unix() func to convert it into an epoch timestamp: import(“time”) func getEpochTime() int64 { return time.Now().Unix() } If you would convert a time string
Read more
How to get the epoch timestamp in PHP?
Posted onIn PHP, how to get the epoch timestamp, the number of seconds passed since the epoch? In PHP, you can use the time() function. ts = time(); To get the microsecond together too as a float number, use the microtime(true) function. ts2 = microtime(true); Example: $ php -a Interactive shell php > echo time() .
Read more
How to get the epoch timestamp in Perl?
Posted onIn Perl, how to get the epoch timestamp, the number of seconds passed since the epoch? In Perl, to get the epoch time, call the time function: my $ts = time Example: $ perl -e ‘print time . “n”‘ 1491473202
How to get an environment variable in Java?
Posted onIn Java, how to get the value (string) of an environment variable? You may call the System.getenv(name) library function in Java to get the environment variable value. public static String getenv(String name) Parameters: name – the name of the environment variable Returns: the string value of the variable, or null if the variable is not
Read more
How to get the epoch timestamp in Bash?
Posted onIn Bash, how to get the epoch timestamp, the number of seconds passed since the epoch? In Bash, you can call the date command with format option “+%s”: date +%s Here, “%s” means: %s seconds since 1970-01-01 00:00:00 UTC
How to get the epoch timestamp in Python?
Posted onIn Python, how to get the epoch time (the number of seconds since epoch)? In Python, you can get the epoch time by calling time.time() which return a floating number: import time print time.time() If you would like to get only the number of seconds, you may convert it to an integer. One example is
Read more