Forum Discussion
Setting $hostname variable
Hello,
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.
- Simon_Blakely
Employee
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
- TimRiker
Cirrocumulus
On bash, $HOSTNAME is already set to the current hostname.
https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Bash-Variables
- Mahi
Cirrus
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
Cirrocumulus
I'm not sure how to reference variables in tmsh. This works though:
# tmsh save /sys ucs $HOSTNAME-$(date +%Y%m%d%H%M)
- Mahi
Cirrus
Thanks Tim, that is working.
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com