Querying Nodes, Events, Schedules and Sessions from the TSM Server

  • QUERY NODE – display the information about one or more registered nodes;
  • QUERY EVENT – display the status of scheduled events;
  • QUERY SCHEDULE – display information about one or more schedules;
  • QUERY SESSION – display information about node sessions.

Querying Nodes

Display the information on all registered client nodes:

tsm> query node

Display the information on the node named JOHN2013:

tsm> query node JOHN2013

Display complete information on the node named JOHN2013:

tsm> query node JOHN2013 format=detailed

Read more

Querying Events

Display the information for 10 days, for all events, scheduled on the node named JOHN2013:

tsm> query event * * begindate=-10 enddate=today node=JOHN2013

Display the complete information for 10 days:

tsm> query event * * begindate=-10 enddate=today format=detailed node=JOHN2013

Display the information, for all events, scheduled on the node named JOHN2013, during specific days:

tsm> query event * * begindate=01/15/2013 enddate=01/20/2013 node=JOHN2013

Read more

Querying Schedules

Display the information on all registered schedules:

tsm> query schedule

Display the information about schedule INCR_20H in domain STANDARD:

tsm> query schedule STANDARD INCR_20H

Display the complete information about schedule INCR_20H:

tsm> query schedule * INCR_20H format=detailed

Display associated schedules, for the node named JOHN2013:

tsm> query schedule node=JOHN2013

Display nodes associated with a schedule INCR_20H:

tsm> query association * INCR_20H

Display nodes without associated schedule:

tsm> SELECT node_name FROM nodes WHERE node_name NOT IN \ 
(SELECT node_name FROM associations)

Read more

Querying Sessions

Display the information on all current sessions:

tsm> query session

Display the information on sessions from a node named JOHN2013:

tsm> SELECT client_name,session_id,start_time,CAST(bytes_sent/1024/1024 \
AS DEC(8,2)) AS "MB_Sent", CAST(bytes_received/1024/1024 AS DEC(8,2)) \ 
AS "MB_Rcvd" FROM sessions WHERE client_name='JOHN2013'

Read more

HowTo: Check If a String Exists

Sometimes, we need to check if the pattern presents in a file and take some actions depending on the result.

It can be done with the help of ‘exit status codes’. Each Linux command returns a status when it terminates normally or abnormally

You can use command exit status in the shell script to display an error message or perform some sort of action.

Syntax

grep -q [PATTERN] [FILE] && echo $?
  • The exit status is 0 (true) if the pattern was found;
  • The exit status is 1 (false) if the pattern was not found.

Examples

Here are some examples of checking if the string, that contains some pattern, presents it the file.

Example 1:

The following example shows that ‘SOME_PATTERN’ presents in ‘SOME_FILE’.

grep -q 'SOME_PATTERN' 'SOME_FILE' && echo $?
0

Example 2:

The next example shows that ‘ANOTHER_ONE_PATTERN’ doesn’t present in ‘SOME_FILE’.

grep -q 'ANOTHER_ONE_PATTERN' 'SOME_FILE' && echo $?
1

Example 3:

Checking if the string presents, and printing the error message if it doesn’t.

grep -q 'PATTERN' 'FILE' || echo "Error: The Pattern Does Not Exist";

Output:

Error: The Pattern Does Not Exist

BASH Script

Let’s check if the pattern exist in the file. If it exists, we will print all the strings that contain the pattern. If it doesn’t exist we will print the error message and stop the script.

#!/bin/bash
PATTERN=$1
FILE=$2
if grep -q $PATTERN $FILE;
 then
     echo "Here are the Strings with the Pattern '$PATTERN':"
     echo -e "$(grep $PATTERN $FILE)\n"
 else
     echo "Error: The Pattern '$PATTERN' was NOT Found in '$FILE'"
     echo "Exiting..."
     exit 0
fi

Save the script, give the execute permissions and execute:

chmod +x script.sh
./script.sh root /etc/passwd
Here are the Strings with the Pattern 'root':
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
./script.sh John /etc/passwd
Error: The Pattern 'John' was NOT Found in '/etc/passwd'
Exiting...

Using SED and AWK to Print Lines Between Two Patterns

From the following article, you’ll learn how to print lines between two patterns in bash.

I’ll show how to to extract and print strings between two patterns using sed and awk commands.

I’ve created a file with the following text.

It’ll be used in the examples below, to print text between strings with patterns.

I Love Linux
***** BEGIN *****
BASH is awesome
BASH is awesome
***** END *****
I Love Linux

Lets say we need to print only strings between two lines that contain patterns ‘BEGIN’ and ‘END’.

Print Lines Between Two Patterns with SED

With the sed command, we can specify the starting pattern and the ending pattern, to print the lines between strings with these patterns. The syntax and the example are shown below.

Syntax:

sed -n '/StartPattern/,/EndPattern/p' FileName
Option Description
-n, –quiet, –silent Suppress automatic printing of pattern space
p Print the current pattern space

Example:

sed -n '/BEGIN/,/END/p' info.txt
***** BEGIN *****
BASH is awesome
BASH is awesome
***** END *****

Print Lines Between Two Patterns with AWK

Similar to the sed command, we can specify the starting pattern and the ending pattern with the awk command.

Syntax:

awk '/StartPattern/,/EndPattern/' FileName

Example:

awk '/BEGIN/,/END/' info.txt
***** BEGIN *****
BASH is awesome
BASH is awesome
***** END *****

Bash: Test If File Exists

While creating a bash script, it is commonly helpful to test if file exists before attempting to perform some action with it.

This is a job for the test command, that allows to check if file exists and what type is it.

As only the check is done – the test command sets the exit code to 0 (TRUE) or 1 (FALSE), whenever the test succeeded or not.

Also the test command has a logical “not” operator which allows to get the TRUE answer when it needs to test if file does not exist. (more…)

HowTo: Change a User’s Password in MySQL

Changing a MySQL user’s password is a task handled by the database administrator (root).

Once the MySQL user’s password is changed, you should update the user’s privileges.

Step 1: Log into MySQL server as root

$ mysql -u root -p

Step 2: Use ‘mysql’ database

mysql> use mysql;

Step 3: Change password for user John

mysql> update user set password=PASSWORD('NEW-PASSWORD-HERE') where User='John';

Step 4: Reload privileges

mysql> flush privileges;

Adding RHEL DVD as Repository

Perform the next steps to add RHEL installation DVD as repository.

Step 1: Create mount point and mount the DVD

$ mkdir /mnt/rhel-dvd && mount -t iso9660 -o ro /dev/cdrom /mnt/rhel-dvd

Step 2: Create RHEL repo list and call it ‘rhel-dvd.repo’

$ touch /etc/yum.repos.d/rhel-dvd.repo

Step 3: Add the following config to ‘rhel-dvd.repo’

[rhel-dvd]
name=Red Hat Enterprise Linux $releasever - $basearch - DVD
baseurl=file:///mnt/rhel-dvd/
enabled=1
gpgcheck=0

Step 4: Clean your cache

$ yum clean all

Now you can install the new software from the DVD using ‘yum install’ command.

Restoring Data from the TSM Server — TSM Client Command Line

The following guide describes how to restore files and folders from TSM Server using TSM Client command line.

The basic syntax for restoring data from TSM is the following:

tsm> restore [source-file] [destination-file]

If the destination of restoration is omitted, then the TSM will restore the file to its original location.

By default, the TSM restores the most current active version of a file.

Restoration of a Single File

To specify a directory as a destination, you need to add slash “/” at the end of the destination path of restoration. Note that the TSM may overwrite a file of the same name in the destination directory.

tsm> restore /home/john/MyFile.txt  /home/john/restore/

The following example demonstrates that the restored file will be named MyFile-rest.txt.

tsm> restore /home/john/MyFile.txt   /home/john/restore/MyFile-rest.txt

Restoration of Multiply Files

Multiply files can be restored using “file by file” restoration like above, or using wildcards.

Available wildcards

  • ? – for a single character substitution;
  • * – for multiple characters substitution.

ATTENTION: You cannot use wildcards in the names of the folders.

Examples:

tsm> restore /home/john/MyFi?e.txt  /home/john/restore/ 
tsm> restore /home/john/*.txt   /home/john/restore/

Restoration of Multiple Files and Folders

To restore a full directory and the contents of all its sub-directories you need to use -subdir=yes option.

tsm> restore -subdir=yes /home/john/files/*  /home/john/restore/

Restoration of Entire Partitions

Essentially, the syntax is the same as in “Restoration of Multiple Files and Folders” above. However, the obvious caveats are to ensure that you have enough space in the destination partition.

tsm> restore -subdir=yes /home  /tmp/restore/

Point in Time Restoration

Here is the syntax for the restoration of a single file for specific date and time . Syntax is the same for the other cases.

There are three different types of date available for restores:

  • todate – will restore all ACTIVE and INACTIVE files backed up BEFORE the date specified;
  • fromdate – will restore all ACTIVE and INACTIVE files backed up AFTER the indicated date;
  • pitdate – will restore only the files that were ACTIVE on the day specified.

You can use -*date and -pittime options together or separately.

tsm> restore -pitdate=MM/dd/YYYY -pittime=hh:mm \
/home/john/MyFile.txt  /home/john/restore/
  • MM – a month
  • dd – a day
  • YYYY – a year
  • hh – an hour
  • mm – minutes

TIP: The format of pitdate command differs upon the clients. Use the same format as your client uses.

Restoration of Old or Deleted Files

As with the GUI, TSM does not, by default, list or restore old and deleted inactive versions of files and directories.

If you want to restore a such file, you need use the -inactive and -pick options.

The -pick option causes TSM to display a list of files from which you can pick.

Issuing a restore as below will display a pick window.

tsm> restore -subdir=yes  -inactive -pick /home/john/*  /tmp/restore/

In a pick interface you will be able to select files to restore via the numbers.

Remember to issue the destination path of restoration with the original restore command if you want to prevent overwriting current versions of files with older versions.

Remote Hard Reset of a Linux Server if Reboot Doesn’t Work

Sometimes, reboot or shutdown -r now, don’t work anymore.

That really sucks, especially if you have no access to the server room or you just don’t want to get up.

But there is another solution if your Kernel is compiled with CONFIG_MAGIC_SYSRQ (sysrq-trigger).

If so, you have the possibility so send binding command.

Reset your server (like pressing the hardware RESET button):

# echo b > /proc/sysrq-trigger

But, it might be a good idea to sync the hard disks before:

# echo s > /proc/sysrq-trigger

More information about “Magic SysRq key”

Generating Random Passwords in the Linux Command Line

You can use the following command to generate the random password:

$ tr -dc A-Za-z0-9 < /dev/urandom | head -c 8 | xargs

Sample output:

4fFUND1d

You can create a bash shell function as follows (add to your ~/.bashrc):

# Random password generator
genpasswd() {
tr -dc A-Za-z0-9 < /dev/urandom | head -c ${1:-8} | xargs
}

Reload .bashrc file.

$ . ~/.bashrc

Now use genpasswd to generate random passwords:

$ genpasswd
vmuWt7TS
$ genpasswd 10
ymkIgxcdCh
$ genpasswd 16
wQnqgdc5tAQoiBdf

HowTo: Check Fan Tray status on Cisco

Execute one of the following commands to check the status of fans on Cisco equipment.

Use the ‘show environment | include fan-tray‘ command to check Fan-Tray status.

# show environment | include fan-tray
system minor alarm on fan-tray 1 fan-fail (raised 00:22:13 ago)
fan-tray 1:
  fan-tray 1 type: WS-C6K-9SLOT-FAN
  fan-tray 1 version: 1
  fan-tray 1 fan-fail: failed

Or use ‘show environment status fan-tray‘ command.

# show environment status fan-tray
fan-tray 1:
  fan-tray 1 type: WS-C6K-9SLOT-FAN
  fan-tray 1 version: 1
  fan-tray 1 fan-fail: failed

You can also check temperature using ‘show environment temperature‘ command.

# show environment temperature
  VTT 1 outlet temperature: 24C
  VTT 2 outlet temperature: 26C
  VTT 3 outlet temperature: 25C
  module 1 outlet temperature: 24C
  module 1 inlet temperature: 26C
  module 1 device-1 temperature: 33C
  module 1 device-2 temperature: 33C
  RP 1 outlet temperature: 30C
  RP 1 inlet temperature: 34C
  EARL 1 outlet temperature: 30C
  EARL 1 inlet temperature: 26C