Showing posts with label tui. Show all posts
Showing posts with label tui. Show all posts

Thursday, April 2, 2009

Command Line Veritas NetBackup Activity Monitor For Linux And Unix

Hey there,

Many of you who use FeedBurner (or whatever smaller, productive, company Google's bought out this week ;) to get blog posts by email have probably already gotten this post even before I finished writing it. I made the cardinal sin of hitting the enter key while I wrote this post online :P I apologize for your (quite understandable) previous confusion ;)

Today's post will be short and sweet, since it's getting late in the day and I'm still working and I don't think I get to sleep in tomorrow either... With that in mind, I tried to make this post heavier on content and have been working on it (on and off) all day. Again, I also apologize for the quality of the video attached to this post, which shows the output of the script. It's very very slow and does not accurately reflect the refresh rate of the PuTTY terminal I was running the program on ;) I had to download 3 or 4 different video processing "portable apps" so that I could try and put something together. I'm not "allowed" to install anything anywhere except for my desktop (and I'm not really sure if that's 100% kosher, which is why those programs are no longer installed) and I had to take what I could get.

Today's Bash script is my first attempt at rewriting one of those oldies-but-goodies that got away. A few years ago, I wrote a TUI Activity Monitor for Veritas NetBackup (In Perl, not like this one in Bash), since that was the only thing I ever used the GUI for. Somehow, over the years, I misplaced the CD (or maybe floppy ;) that I had it saved on and I've finally come to peace with the fact that I'll probably never ever find it again.

This script is much less glitzy than the old one, but it's a good starting point, and I hope a few people (aside from me ;) find it useful. It's a very simple program to run, since it only takes one optional variable (The refresh rate in seconds - defaulted at 10) and, as yet, does not have any special functionality built in. And, yes, you should read that as "The output formatting is God Awful!" :)

Check out the video below to watch a few backup jobs, and a catalog job, run in slooooooooooooooooooo-mo ;) Then grab the script and put it to good use. If you can make it better (I know I can, so there must be thousands of you out there who can, too :), feel free to improve upon it before I get around to that. I try to stay away from exporting Java GUI's over X-Windows as often as I possibly can (especially when working on systems overseas or across-country), and I've been meaning to rewrite this script for a long long time.

If this video makes you feel drowsy, download it and play it at double speed in the player of your choice. For some reason, it recorded at half speed and I ran out of time to try and figure out why ;)



And here's the script. Enjoy it and abuse it in good health :)


Creative Commons License


This work is licensed under a
Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License

#!/bin/bash

#
# nbuvtam - v1 of the netbackup vt activity monitor
#
# 2009 - Mike Golvach - eggi@comcast.net
#
# Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License
#

trap 'exit 0' 2
perl=`which perl`

if [ ! -z $1 ]
then
refresh=$1
else
refresh=10
fi

function local_time()
{
regular_time=$(perl -e "print scalar(localtime($1))")
echo -n "$regular_time"
}


jobtype_array=(backup archive restore verify duplicate import catalogue_backup vault label erase tape_request clean format_tape physical_inventory qualification)
state_array=(queued active wait_for_retry done)
operation_array=(mount position connect write vault_initialize vault_duplication vault_duplication_complete vault_catalog_backup vault_eject report duplicate import verify restore catalog_backup vault label erase)
subtype_array=(immediate scheduled user_initiated quick_erase long_erase)
schedule_type_array=(full incr user_backup user_archive cumulative_incr)

tput clear
OLDIFS=$IFS
IFS=","
while :
do
tput clear
echo "======================================================================="
echo "THE TOTALLY LAME VERITAS NETBACKUP COMMAND LINE ACTIVITY MONITOR"
echo "V0.0000000001-alpha - Ctl-C to Quit"
echo "======================================================================="
echo "jobid type state state_details status policy schedule client media_server start_time elapsed_time end_time storage_unit attempt operation kilobytes files pathname percent_complete job_pid owner master"
echo "======================================================================="
echo "======================================================================="
while read jobid jobtype state status policy schedule client server started elapsed ended storage_unit attempt operation kilobytes number_of_files path_last_written percent jobpid owner subtype classtype scheduled_type priority group master_server retention_unit retention_period compression kb_last_written files_last_written file_list_count files the_rest
do
start_time=$(local_time $started)
end_time=$(local_time $ended)
elapsed=$(echo $elapsed|sed 's/^0*//g')
hours=$((elapsed / 3600))
elapsed=$((elapsed % 3600))
minutes=$((elapsed / 60))
elapsed=$((elapsed % 60))
if [[ $hours -lt 10 ]]
then
hours="0$hours"
fi
if [[ $minutes -lt 10 ]]
then
minutes="0$minutes"
fi
if [[ $elapsed -lt 10 ]]
then
elapsed="0$elapsed"
fi
echo "$jobid ${jobtype_array[${jobtype}]} ${state_array[${state}]} ${operation_array[${operation}]} $policy ${schedule_type_array[${schedule}]} $client $server $start_time $elapsed_time $end_time $storage_unit $attempt $operation $kilobytes $number_of_files $path_last_written ${percent}% $jobpid $owner $master_server"
echo "---------------------------------------------------------------"
done <<< "`/usr/openv/netbackup/bin/admincmd/bpdbjobs -all_columns|head -5`"
sleep $refresh
done
, Mike




Discover the Free Ebook that shows you how to make 100% commissions on ClickBank!



Please note that this blog accepts comments via email only. See our Mission And Policy Statement for further details.

Friday, June 13, 2008

Using NTSYSV To Manage Linux Services

Hey There,

Picking up where we left off in yesterday's post regarding using chkconfig to manage Linux run levels, today we're going to take a look at another common, and helpful, tool you can find on Redhat, Fedora and other such similar Linux distro's, named ntsysv. Actually, we'll be looking at two commands, since there's a slight dependency (which we'll get to befoe this post is over) between ntsysv and another command named service.

Click on the image below to see it in its unaltered state ;)

The intuitive user interface for ntsysv

ntsysv is a great tool to use if you like GUI-based interaction and aren't able to run an X-Windows session. Since it's basically a tty GUI (Sometimes referred to as a TUI), you can enjoy the graphical interaction through any terminal software that supports basic color in the shell.

You may also have noted, in the past, that the menu we created in our post on creating a simple menu using tput and ANSI colors looks eerily similar. This is only true at the base level, as our TUI menu was much more limited. Check out either of the above links for pictorial depictions of all the various very-portable colors you can use in the shell and some good information on how to make use of color in your Linux shell.

Back to ntsysv :) This command is very simple to use and can be invoked in only a few ways. The most common is without arguments, like this:

host # ntsysv

This will bring up the TUI, which should look roughly like the image near the top of this post. The contents of the ntsysv interface will probably differ, since it's populated with the names of packages (or services) that you have installed on your system and that it is able to control. The interface is very simple to use and the interaction basically consists of your either checking, or unchecking, the box next to the service name on any given line. When you exit ntsysv (by selecting OK or Cancel), all the services that have their checkboxes checked, will be considered active, and the unchecked services will be rendered inactive (see below for a small "gotcha" concerning ntsysv's specific behaviour in this matter).

By default, when you invoke ntsysv with no command line arguments, you'll be editing only the run level at which you invoke it. So, if your system is at run level 3 and you just run ntsysv, you'll only be editing the on/off functionality of services at run level 3. If you want to be more specific, and make changes across multiple run levels, you can specify that at the command line when you invoke the program, like so:

host # ntsysv --level 2345

The above, for instance, would bring up the same interface, but you'd be editing run levels 2, 3, 4 and 5 all at the same time. The other nice thing about this command is that, unlike using chkconfig to manage run levels you'll just be using your space bar (or mouse, depending on how you have your setup set up ;) to check and uncheck boxes, rather than typing on or off on a per-service basis. A workaround to that is posted in yesterday's write up on chkconfig, but ntsysv has that functionality bundled in. On the flipside of the coin, you can't use ntsysv to add new services. You only get to work with what the TUI shows you.

Some versions of ntsysv also have a --back flag that you can use to modify the look and feel of the Cancel button (in other words, it will change the text on the Cancel button to Back). Useful? You be the judge ;)

host # ntsysv --back <-- Note that this can also be used in conjunction with the --level flag.

And, for that "gotcha" I promised to deliver way back near the top of this post ;) This is something to keep in mind if you need changes to be enacted "immediately." ntsysv's default behaviour is to automatically start (or stop) a service, after you've select/unselected it in the TUI and entered OK. But, this automatic starting and stopping of services only works for services managed by xinetd.

If you, for instance, wanted to stop any service not managed by xinetd (which you can determine by looking for it in the /etc/xinetd.d directory), you would need to follow up your ntsysv session by stopping the service with the "service" command, like so:

host # service SERVICENAME stop

Of course, if you want to start it up, you'd use "start" in place of the "stop" directive (other options for the "service" command include restart, status, etc, and can be highly specific to the service itself since those directives are derived from the specific service's init script). If you don't do this, for services not managed by xinetd, your changes won't take place until run levels change in the appropriate manner (like during a reboot, for instance).

For those of you who've never used ntsysv, I'd suggest giving it a try. While it is limited, it's a great tool for getting tedious work done simply and can also be a great way to visually check on the status of services at any run level.

Enjoy :)

, Mike