Learning to leverage tabcmd
In the following examples you’ll see progressively more advanced ways to use tabcmd including:
Manually creating and running a tabcmd script
Creating a windows batch (.bat) file to run a saved script
Using windows task scheduler to automatically run a saved script
Manually entering and running a script in tabcmd
The most basic way of using tabcmd is to manually enter commands that can also be accessed from the tableau server manual. This is also a good way to test tabcmd before you attempt to create a script that automatically runs tabcmd.
A common task required for a content administrator is to create groups on the server and assign users to those groups. Figure 11.6 displays the script used to create a new group called executives.
Figure 11.6 Adding a new group to a server
The first command in figure 11.6, tabcmd login, initiates a new session and prompts the user to enter a password. It is also possible to affix the password to the end of the login command by adding –p or -password followed by your actual password. The script tabcmd create group “executives” triggers the addition of the new group to a server. At the bottom of the script you can see that tabcmd provides a status while processing and then confirms that the operation is succeeding.
The next step is to assign users to the group. By creating a list of valid usernames (egroupadd.csv) and saving it in the tableau server bin folder, tabcmd can assign specified users to the executive group. Figure 11.7 shows a list of server users on the left (Allen, bill, Cal, Dave, Eric). On the right you can see the executed script.
Figure 11.7 Adding users to the new group
This is the script used to add the users: tabcmd add users “executives” -users “eggroupadd.csv”.
These activities can be done directly into the tableau server GUI environment, but tabcmd may be a more efficient way to make group assignments if they change frequently or when you have a large number of users to assign.
Running tabcmd scripts via batch files
If you find yourself using the same script repeatedly, you can use a text editor to create and save the script for reusing it later. Windows includes a text editor program called notepad that can be used to enter and save tabcmd script. Notepad is normally located in the windows accessories folder. Another windows application-task scheduler-can be used to launch the script saved using notepad. There are many other programming tools you can use for this purpose, but they form the essential part of windows toolset.
The steps required to create batch processing scripts
Regardless of whether you prefer to use windows notepad or any other text editing software, the basic steps to create a batch process are the same:
Create the tabcmd script in notepad or another text editor.
Save the script as a (.bat) executable file.
Double-click the batch file to execute the script.
In this scenario the script still runs manually and you no longer have to type all of the instructions each time you want to make changes, export data, or update files. They may be the activities you repeat periodically-often enough to warrant saving a script-but not so often that you need to fully automate processing.
In the next example, you’ll see how to create a script in a text editor, save the script as a batch file, and then run the script using a CSV source file that provides the usernames and permissions needed to update tableau server.
Assume that you have five new users to add and you will be provisioning, interactor licenses for all of them. Figure11.8 shows the CSV file with the names of the users.
Figure 11.8 Csv file containing the new user list
The ultimate goal is to Create a robust script that will work flexibly. To make it possible, you require a little knowledge on window commands and tabcmd. Figure 11.9 shows one way to accomplish adding the users.
Figure11.9 Creating and saving script in a bat file
For the batch file to run properly, place it in the same directory as the CSV file that contains the users that need to be added to the server. The first line of the code in figure 11.9 -@set PATH=%PATH%-defines the path for the file to search if any elements are not located there. These window commands allow you to define the path for the batch session only. This is a better practice than blending data file with windows system files (not a good practice). It also has the virtue of persisting only while the batch file is being executed-rendering to the earlier example of permanently editing the PATH system variable unnecessarily.
The rest of the script in figure 11.9 includes tabcmd commands that are located in the bin folder specified by the set path command. In fact, you can define many other different paths using this method for files that you want to keep separated.
The bulleted list below may be easier to read than figure in 11.9. Alter the specific code where applicable, to match your system’s setup and the name of the CSV file that you have created to load new users.
Line2-Log in to tableau server.
Line3-Create the users from the new users.csv file.
Line4-Log out of tableau server.
When the program starts you’ll see each command run and when it is finished the command window will close automatically. Figure 11.10 shows a screen shot of the windows command processor window-running the script.
Figure 11.10 The executed script
As the program finishes, the screen gets automatically cleared. If you want to keep it in view, add a fifth line to the script using the pause command. With just a few lines of code you can update many records this way. If you aren’t using active directory to secure tableau server, this method provides a quick way to mass load hundreds of users from a file.
Using windows scheduler to fully automate scripts
By adding the batch file from the previous example to the windows task scheduler, the file can be updated based on a trigger event or a specific time schedule. For example, if you have an actively expanding user base, it might be necessary to create new users in the system every day. The system administrator could add new users to the createuser.csv and schedule updates every day at a specific time. Figure 11.11 shows the task scheduler application. A new task was created to ADD USERS to tableau server (daily). The following steps are used to define the schedule:
General tab – names and describes the task and set security options.
Triggers tab – defines what causes action (daily at 7:00AM).
Actions tab – select the batch file to run (point to the createuser.bat file).
Conditions tab – set desired limitations of the run to occur.
Settings tab – specify additional settings affecting the task behavior.
This will cause the file to be updated on a regular basis without the need for the batch file to be manually selected. Figure 11.11 shows the task scheduled for automatic updates of new user additions.
Figure 11.11 Windows task scheduler
Even if you’re on vacation, updates can continue if you delegate the task of adding the usernames and license level to the new users.csv
List Of Tableau Courses:
|Data Visualization and Dashboarding Fundamentals|
Stay updated with our newsletter, packed with Tutorials, Interview Questions, How-to's, Tips & Tricks, Latest Trends & Updates, and more ➤ Straight to your inbox!
|Tableau Training||Dec 12 to Dec 27||View Details|
|Tableau Training||Dec 16 to Dec 31||View Details|
|Tableau Training||Dec 19 to Jan 03||View Details|
|Tableau Training||Dec 23 to Jan 07||View Details|
As a Senior Writer for Mindmajix, Saikumar has a great understanding of today’s data-driven environment, which includes key aspects such as Business Intelligence and data management. He manages the task of creating great content in the areas of Programming, Microsoft Power BI, Tableau, Oracle BI, Cognos, and Alteryx. Connect with him on LinkedIn and Twitter.
Copyright © 2013 - 2023 MindMajix Technologies