Forum Discussion

Mahi's avatar
Icon for Cirrus rankCirrus
Nov 14, 2019

Setting $hostname variable



I want to setup the environment variable referring the hostname of the current device and use it in multiple commands such as tcpdump as follows.

tcpdump -nni 0.0 -s0 -w /var/tmp/$hostname_$date_$time.pcap


If there any simple way to do that? once a variable is setup, I can copy paste the same command on multiple LTM devices so as to speed up the troubleshooting. Thank you in advance.

5 Replies

  • Mostly, it looks to be like you want a bash alias (for things like date or time).

    But you can also do this with bash command substitution which might be better as you need no local configuration (creating aliases or environment variables)

     tcpdump -nni 0.0 -s0 -w /var/tmp/$(/bin/hostname)_$(date +%Y-%m-%d)_$(date +%H:%M).pcap
    tcpdump -nni 0.0 -s0 -w /var/tmp/localhost.localdomain_2019-11-14_15:48.pcap
  • Thank you, I was looking for something like this. While it worked for 'tcpdump', it didn't for taking UCS archive via CLI.

    (tmos)# save /sys ucs  $HOSTNAME
    Error, invalid characters in UCS file name. The dash, period, forward-slash, plus sign, and underscore are the only special characters allowed.
    Error during config save.
    Unexpected Error: UCS saving process failed.
    • TimRiker's avatar
      Icon for Cirrocumulus rankCirrocumulus

      I'm not sure how to reference variables in tmsh. This works though:

      # tmsh save /sys ucs $HOSTNAME-$(date +%Y%m%d%H%M)