-3

I am using NetScaler FreeBSD, which recognizes many of the UNIX like commands, grep, awk, crontab… etc.

I run the following command to get the number of connected users that we have on the system

#> nsconmsg -g aaa_cur_ica_conn -d stats

OUTPUT (numbered lines):

Line1: Displaying current counter value information
Line2: NetScaler V20 Performance Data
Line3: NetScaler NS11.1: Build 63.9.nc, Date: Oct 11 2019, 06:17:35
Line4:
Line5: reltime:mili second between two records Sun Jun 28 23:12:15 2020
Line6: Index reltime     counter-value symbol-name&device-no
Line7:     1 2675410                 605 aaa_cur_ica_conn
…
…

From above output - I only need the number of connected users (represented in Line 7, 3rd column (605 to be precise), along with the Hostname and Time (of the running script)

Now, to extract this important 3rd column number i.e. 605, along with the hostname, and time of data collected - I wrote the following script:

printf '%s - %s - %s\n' "$(hostname)" "$(date '+%H:%M')" "$(nsconmsg -g aaa_cur_ica_conn -d stats | grep aaa_cur_ica_conn | awk '{print $3}')"

The result is perfect, showing hostname, time, and the number of connected users as follows:

Hostname - 09:00 – 605

Now can anyone please shed light on how I can:

  • Run this script every day - 5am to 5pm (12hours)?
  • Each time scripts runs - append a file on a remote Unix share with the output?

I appreciate this might be a bit if a challenge... however would be grateful for any bash scripts wizards out there that can create magic!

Thanks in advance!

nbari
  • 25,603
  • 10
  • 76
  • 131
Newbie
  • 5
  • 5

1 Answers1

0

I would suggest a quick look into the FreeBSD Handbook or For People New to Both FreeBSD and UNIX® so that you could get familiar with the operating system and tools that could help you achieve better what you want.

For example, there is a utility/command named cron

The software utility cron is a time-based job scheduler in Unix-like computer operating systems.

For example, to run something all days between 5am to 5pm every minute, you could use something like:

* 05-17 * * * command

Try more options here: https://crontab.guru/#*_05-17_*_*_*.

There are more tools for scheduling commands, for example at (https://en.wikipedia.org/wiki/At_(command)) but this something you need to evaluate and read more about it.

Now regarding the command, you are using to get the "number of connected users", you could avoid the grep and just used awk for example:

awk '/aaa_cur_ica_conn/ {print $3}'

This will print only column 3 if line contains aaa_cur_ica_conn, but as before I invite you to read more about the topic so that you could bet a better overview and better understand the commands.

Last but not least, check this link How do I ask a good question? the better you could format, and elaborate your question the easy for others to give an answer.

nbari
  • 25,603
  • 10
  • 76
  • 131
  • Hiya nbari, really appreciate you taking the time provide feedback and learning resources... THANK YOU. – Newbie Jul 01 '20 at 16:26
  • Looks like I have steep learning curve... will take a week or two to get my head round > test etc.. so will feedback asap. – Newbie Jul 01 '20 at 16:28