Zenity Linux Command

What is Zenity?

Zenity is a program that will display GTK+ dialogs, and return the user's input. This allows you to present information, and ask for information from the user, from all manner of shell scripts.

SYNOPSIS

zenity [options]

Some of the features of Zenity

  • FOSS (Free and Open Source Software): Free and open-source software is software that is both free software and open-source software where anyone is freely licensed to use, copy, study, and change the software in any way, and the source code is openly shared so that people are encouraged to voluntarily improve the design of the software.
  • Cross-Platform Application: allow different software systems — typically Windows, Mac, and Linux (Android is built on top of Linux) — to exchange information, usually by the creation of a single program that operates on all these operating systems.
  • Allows GTK+ Dialog Box Execution: Variable to use it later when executing the shell script with gtkdialog.
  • Command Line Tool
  • Support in Shell Scripting

Installation of Zenity

Zenity is by default installed or available in the repository of most of the Standard Linux distributions of today. You can check it is installed on your machine or not by executing the following commands.

>> zenity --version
>> whereis zenity 
>> sudo apt-get install zenity 
 >> sudo yum install zenity 

Zenity Basic Dialog Boxes

Some of the basic Dialogs of Zenity, which can be invoked directly from the command line.

  • Calendar
  • File selection
  • Forms
  • List
  • Notification icon
  • Message
  • Error
  • Information
  • Question
  • Warning
  • Password entry
  • Progress
  • Text entry
  • Text information
  • Scale
  • Color selection
  • Many more…
Different types of Zenity
#First Name
>> first_name=`zenity --title="First name" --entry --text="Enter first name"`
#Second Name
>> second_name=`zenity --title="second name" --entry --text="Enter Second name"`
>> zenity --question --text="Are You Indian citizen" && zenity --password > password.txt || zenity --warning --text="Sorry your not eligible to proceed"
>> zenity --list --title="LOGABLE USERS" --column="FIRST NAME" --column="LAST NAME" --column="PASSWORD" --column="DOB" $first_name $second_name $password $dob --text="User Details" --width="800" --height="400"

Creating Script to Manage Linux Users

This script will perform Creating, Removing, and Displaying all users

Script-1 for creating a new user

>> vim newUser
  • BashBang( !# ) this will says what to use for running code
  • The below line just stores to userad User name and password given by the user
userad=$(zenity --username --password --title="Login")
  • Both lines will cut the user name and password and store to different variables, -f is for representing column
>> user=$(echo $userad | cut -d"|" -f1)
>> password=$(echo $userad | cut -d"|" -f2)
  • Adding a new user => sudo useradd -m $user
  • Attaching password => echo $password | sudo passwd $user — stdin &> /dev/null
  1. If a user gives password takes or else takes null as password
  2. — stdin takes input as a password and stores
  • Once finished prompts with succsss
zenity — info — title=”User $user created” — text=”SUCCESS”
>> chmod 755 newUser
>> ./newUser
Successfully user Created

Removing a User Script-2

vim delUser
chmmod 755 delUser

Execute Script-2 to remove a user

Deleted

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Vinodha kumara

Vinodha kumara

ARTH-School of technology, BCA graduate