Often we write shell scripts and at one point we would like to display messages or otherwise interact with the user using a graphical way, without rewriting all our script in C.
A small program called gtk-shell was created for that purpose. It is a GTK-based program meant to be used in shell scripts, that can interact with the user, and even return values to the script. Let's see a very simple example:
xv -quit -root `gtk-shell -t "Which file do you want me to use?" -fs`
This will display a graphical browsing box with the specified title, where the user can select a file, and the file path will be returned to xv which will display it as background.
Gtk-shell can be used in many ways including displaying a message, asking for input, and more. Here is an output of "gtk-shell --help":
Command line options:
--help, -h This help text
--version, -v Show gtk-shell's version
--output
--title
--label
--file-selection, -fs Display a file selection box
--size
--position
--query, -q Display a query box
--query-value, -qv Set a value in the query box
--append-eol, -eol Appends an EOL char at output time
--exit-code
--view-file
--edit-file
--button
--choice
Example: gtk-shell -l "Pick a choice" -c 1 2 3 4 -b Ok -eol
Example: xv -quit -root `gtk-shell -t "Which image?" -fs`
Makefile don't equal C
Makefiles are used in most Unix C or even C++ programs. But nowhere does it say that they can't be used for other languages. Make is a program installed with most Linux distributions, and on most Unix systems too. Makefiles make your program portable, and easy to compile. These files can be used in C, C++, Java, and any program that requires compilation.
Make has so many useful applications. Feel free to explore them for your programs.
Who is online?
Many system administrators use scripts to help them in the process of managing a server. A common problem
is finding out exactly what users are on the system and what they are doing.
Several tools are available on the system to see who is online, what processes are running, and pipeing them together can resolve many problems. Here are 2 small scripts that will show, first if a user is online, and then what he is running:
who | grep $1
ps -aux | grep $1
The variable $1 here means the first command line argument, from a shell script. The who command first checks if the user is online, then ps will show all the processes currently running under that user's UID.
0 comments:
Post a Comment