Monday, May 27, 2013

How to check disk space and usage

# Disk space
df -h
df -h /
df -h /home
 
# Disk Usage
du -h /
 
# Disk usage with target folder

du -csh /home/kyfoo

How to kill user login session

Linux Realtime process manupulation



chrt command: Set / Manipulate Real Time Attributes of a Linux Process

by on March 6, 2008 · 3 comments· last updated at March 6, 2008
Q. How do I set the real time scheduling priority of a process under Linux operating system using a shell prompt?

A. You can use chrt command to set or retrieve the real-time scheduling attributes / scheduling priority of an existing PID. You can also run COMMAND with the given attributes.

Understanding Linux Scheduling Priorities

From the man page:
The scheduler is the kernel part that decides which runnable process will be executed by the CPU next. The Linux scheduler offers three different scheduling policies, one for normal processes and two for real-time applications.
  1. SCHED_OTHER - the default universal time-sharing scheduler policy used by most processes.
  2. SCHED_FIFO or SCHED_RR - intended for special time-critical applications that need precise control over the way in which runnable processes are selected for execution
  3. SCHED_BATCH - intended for "batch" style execution of processes
WARNING! These examples requires proper understanding of UNIX / Linux scheduling algorithms; don't try this on production systems; if you are not familiar with Linux scheduling algorithms.

Scheduling Algorithm

  • SCHED_FIFO uses First In-First Out scheduling algorithm
  • SCHED_RR uses Round Robin scheduling algorithm
  • SCHED_OTHER uses Default Linux time-sharing scheduling algorithm
  • SCHED_BATCH use Scheduling batch processes algorithm
WARNING! Standard Linux kernel is used in as a general-purpose operating system and can handle background processes, interactive applications, and soft real-time applications (applications that need to usually meet timing deadlines). chrt command is directed at these kinds of applications.

util-linux package

chrt command is part of util-linux package - low-level system utilities that are necessary for a Linux system to function. It is installed by default under Debian / Ubuntu / CentOS / RHEL / Fedora and almost all other Linux distributions.

How do I use chrt command to get real time attributes of a Linux process?

To get / retrieve the real-time attributes of an existing task / PID, enter:
# chrt -p pid
# chrt -p 112
# chrt -p 1

Output:
pid 1's current scheduling policy: SCHED_OTHER
pid 1's current scheduling priority: 0
Any user can retrieve the scheduling information. No special privileges required.

How do I use chrt command to set real time attributes of a Linux process (already running processes)?

Use the syntax as follows to set new priority:
# chrt -p prio pid
# chrt -p 1025
# chrt -p 55 1025
# chrt -p 1025

Before setting new scheduling policy, you need to find out minimum and maximum valid priorities for each scheduling algorithm, enter:
# chrt -m
Output:
SCHED_OTHER min/max priority    : 0/0
SCHED_FIFO min/max priority     : 1/99
SCHED_RR min/max priority       : 1/99
SCHED_BATCH min/max priority    : 0/0

How do I set SCHED_BATCH scheduling policy?

To set scheduling policy to SCHED_BATCH, enter:
# chrt -b -p 0 {pid}
# chrt -b -p 0 1024

How do I set SCHED_FIFO scheduling policy?

To set scheduling policy to SCHED_FIFO, enter:
# chrt -f -p [1..99] {pid}
Set policy to SCHED_FIFO with 50 priority:
# chrt -f -p 50 1024
# chrt -p 1024

How do I set SCHED_OTHER scheduling policy?

To set policy scheduling policy to SCHED_OTHER, enter:
# chrt -o -p 0 {pid}
# chrt -o -p 0 1024
# chrt -p 1024

How do I set SCHED_RR scheduling policy?

To set scheduling policy to SCHED_RR, enter:
# chrt -r -p [1..99] {pid}
Set policy to SCHED_RR scheduling with 20 priority:
# chrt -r -p 20 1024
# chrt -p 1024

Further readings:

If you run CPU-intensive processes, you should familiarize yourself with other tools:

VNC terminal fail to start session in servers


error message:
"vncserver: couldn't find "xauth" on your PATH"
 
Solution:
1. in terminal, type "whereis xauth"
    "xauth: /usr/X11R6/bin/xauth /usr/bin/X11/xauth"
2. in user home folder, type "vi .profile"
3. update $PATH variable in .profile file by adding "/usr/X11R6/bin/xauth" to the end of the PATH variable.

 

UltraEdit regular expression symbols

 
 

Regular expressions

Regular Expressions are essentially patterns rather than specific strings that are used with Find/Replace operations. There are many ways that regular expressions may be used to streamline operations and enhance efficiency. We have listed below a reference key for both UltraEdit-style and UNIX-style regular expressions as well as some examples to demonstrate how regular expressions may be used in UltraEdit.
Regular Expressions in UltraEdit
UltraEdit Symbol UNIX Symbol Function
% ^ Matches/anchors the beginning of line.
$ $ Matches/anchors the end of line.
? . Matches any single character except a newline character. Does not match repeated newlines.
* Matches any number of occurrences of any character except newline.
+ + Matches one or more of the preceding character/expression. At least one occurrence of the character must be found. Does not match repeated newlines.
++ * Matches the preceding character/expression zero or more times. Does not match repeated newlines.
^ \ Indicates the next character has a special meaning. "n" on its own matches the character "n". "^n" (UE expressions) or "\n" (UNIX expressions) matches a linefeed or newline character. See examples below.
[ ] [ ] Matches any single character or range in the brackets.
[~xyz] [^xyz] A negative character set. Matches any characters NOT between brackets.
^b \f Matches a page break/form feed character.
^p \p Matches a newline (CR/LF) (paragraph) (DOS Files).
^r \r Matches a newline (CR Only) (paragraph) (MAC Files).
^n \n Matches a newline (LF Only) (paragraph) (UNIX Files).
^t \t Matches a tab character.
[0-9] \d Matches a digit character.
[~0-9] \D Matches a non-digit character.
[ ^t^b] \s Matches any white space including space, tab, form feed, etc., but not newline.
[~ ^t^b] \S Matches any non-white space character but not newline.
\v Matches a vertical tab character.
[0-9a-z_] \w Matches any alphanumeric character including underscore.
[~0-9a-z_] \W Matches any character except alphanumeric characters and underscore.
^{A^}^{B^} (A|B) Matches expression A OR B.
^ \ Overrides the following regular expression character.
^(...^) (...) Brackets or tags an expression to use in the replace command. A regular expression may have up to 9 tagged expressions, numbered according to their order in the regular expression.
^1 \1 Numerical reference to tagged expressions. Text matched with tagged expressions may be used in Replace commands with this format.
Note: ^ refers to the character '^' NOT Control Key + value.


UltraEdit/UNIX Regular Expression Examples


Simple String Matching

Simple string matching is probably the most basic form of regular expressions but can allow you to quickly exploit different patterns so that you can search for more than one string at a time rather than doing multiple Find operations.
UltraEdit RegExp:
Find What: m?n
Matches: "man" and "men" but not "moon"

Find What: t*t
Matches: "test", "tonight" and "tea time" (the "tea t" portion) but not "tea
time" (newline between "tea " and "time").

Find What: Te+st
Matches: "test", "teest", "teeeest", etc. but does not match "tst"
UNIX RegExp:
Find What: m.n
Matches: "man" and "men" but not "moon"

Find What: t.*t
Matches: "test", "tonight" and "tea time" (the "tea t" portion) but not "tea
time" (newline between "tea " and "time").

Find What: Te+st
Matches: "test", "teest", "teeeest", etc. but does not match "tst"
 

Wednesday, March 6, 2013

Polaris ATCAtester


Run atcatester for ShMC
Steps:
1. Flash firmware into both CMMs in Chassis.
2. Configure CMM's IP address and submask need to be 255.255.255.0 (if using 255.255.0.0, test script is not possible to able to run it, refer troubleshoot section) *Do NOT change server IP subnetmask.
3. Disable password needed for CMM access on Active CMM
    - cmmset -t level:admin -d authtypes -v none
==>Success
4. Verify the password is not need has been configured.
    - cmmget -t level:admin -d authtypes
==> none
 
5. Goto where atcatester installed, example server01
6. Run atcatester test cases as below (example):
    - esoatcatester -u root -v -c shmctest 128.0.10.78 308
 
 
Troubleshoot:
This is what happen when IP subnetmask is 255.255.0.0
[kyfoo@server ~]$ esoatcatester -u root -v -c shmctest 128.0.10.78 309
* Log into atca_tester_logs/2012_03_27_12_25_50
* Initializing session (128.0.10.78:623)...
* Transport error: Request timed out (NetFn:0x06 Cmd:0x38 Resp:0x20 - GetChannelAuthCapabilities)
 
List of ShMC test cases:
[kyfoo@server ~]$ esoatcatester list shmctest
--- Basic ATCA & IPMI requirements test package ---
--- LEDs requirements test package ---
--- Sensors test package ---
--- Shelf Manager and Shelf test package ---
        300 - Address Table presence and Get Address Info command (ShMC Test)
        301 - Get/Set Shelf Address Info commands (Interactive)(ShMC Test)
        302 - SEL Device (ShMC Test)
        303 - SDR Repository (ShMC Test)
        304 - SDR Repository storage (ShMC Test)
        305 - Temperature Thresholds Crossing (single board,correct order) (ShMC Test)
        306 - Temperature Thresholds Crossing (single board,incorrect order) (ShMC Test)
        307 - Temperature Thresholds Crossing (multi-board) (ShMC Test)
        308 - Temperature Thresholds Crossing (power down/extract board) (Interactive)(ShMC Test)
        312 - Board communication lost/recovered (Interactive)(ShMC Test)
        313 - Board extracted/replaced when communication lost/recovered (Interactive)(ShMC Test)
        315 - Shelf Manager IPMB Address (Interactive)(ShMC Test)
        322 - Temperature Thresholds Crossing (communication lost) (Interactive)(ShMC Test)
        323 - Temperature Thresholds Crossing (multiple power levels) (ShMC Test)
        324 - FRU Inventory Device Lock/Write commands (Interactive)(ShMC Test)
        325 - Insufficient power budget (Interactive)(ShMC Test)
        326 - Shelf Manager Controlled Activation (Interactive)(ShMC Test)
        327 - Shelf Manager Controlled Deactivation (Interactive)(ShMC Test)
--- IPMB related test package ---
        400 - IPMB reliability (w/o an ATCA board) (ShMC Test)
        404 - IPMB hang detection and recovery (IPMB errors on bus) (Interactive)(ShMC Test)
--- RMCP interface requirements test package ---
--- MMC and Carrier IPMC test package ---
--- Description test package ---
        701 - Active Shelf Manager Description (ShMC Test)
---  HPM Tests (IPMC)  ---
---  HPM Tests (MMC)  ---
 
Below are the help from ATCA tester:
Usage: esoatcatester [OPTIONS]... test (ipmc[/frus][:testseq][_sensors])+
       esoatcatester [OPTIONS]... carriertest (ipmc[:testseq][_sensors])+
       esoatcatester [OPTIONS]... mmctest mmc@ipmc[:testseq][_sensors]
       esoatcatester [OPTIONS]... shmctest [testseq]
       esoatcatester [OPTIONS]... shelftest [testseq]
       esoatcatester [OPTIONS]... nettest [testseq]
       esoatcatester [OPTIONS]... list [mode] [testseq]

   hostname: Shelf Manager hostname or IP address.
   testseq: A comma separated list of test numbers
       or test ranges (without any blank character),
       optionnaly followed by a 'not' clause
       (e.g. 1-7,10not2,4-5 is equivalent to tests 1,3,6,7,10).
       Note that 'not10' means all tests except test #10.
       testseq is altered by -i and -I options.
       If no testseq is specified, all possible tests are
       selected according to the given command.
   COMMANDS:
   test (ipmc[/frus][:testseq][_sensors])+
       execute IPMC and FRU test(s).

       ipmc is the IPMB address (in hexadecimal e.g. 0x82
       or 82 mean 0x82) of the IPMC to test.
       frus is a comma separated list of FRUs or FRUs ranges on which
       FRU tests are executed. Non-FRU (IPMC) tests are executed only
       if frus contains '0'. If no frus is specified then '0'
       is added to frus. If frus is equal to 255, then tests
       are executed on all FRUs present on the IPMC.
       Note that frus is subject to the same rules as testseq.
       Instead of ipmc/frus syntax, it is possible to select the FRU to test
       with a character string containing a site type among [board,
       shmc, pem, shelffru, fan, fanfilter, alarm] followed by a
       site number (in decimal e.g. board1, shmc2, fan3, etc...).
       sensors is a comma separated list of sensors numbers
       (in hexadecimal e.g. 0x10 or 10 mean 0x10) or sensors ranges
       on which sensors tests are executed.
   hpmtest ipmc[:testseq]
       execute HPM (IPMC) test(s).

       ipmc is the IPMB address (in hexadecimal e.g. 0x82
       or 82 mean 0x82) of the IPMC to test.
   hpmmmctest mmc@ipmc[:testseq]
       execute HPM (MMC) test(s).

       mmc is the IPMB-L address of the MMC to test.
       ipmc is the IPMB address of the Carrier hosting the Module.
   carriertest (ipmc[:testseq][_sensors])+
       execute Carrier IPMC, IPMC and FRU test(s).

       ipmc is the IPMB address (in hexadecimal e.g. 0x82
       or 82 mean 0x82) of the Carrier IPMC to test.
       Instead of ipmc syntax, it is possible to select the Carrier IPMC
       to test with a character string containing 'board'
       followed by a site number (in decimal e.g. board1, board14, etc...).
       sensors is a comma separated list of sensors numbers
       (in hexadecimal e.g. 0x10 or 10 mean 0x10) or sensors ranges
       on which sensors tests are executed.
   mmctest mmc@ipmc[:testseq]
       execute MMC test(s).

       mmc is the IPMB-L address of the MMC to test.
       ipmc is the IPMB address of the Carrier hosting the Module.
       Instead of mmc syntax, it is possible to select the MMC
       to test with a character string containing 'amcsite'
       followed by a site number (in decimal e.g. amcsite3)
       Instead of ipmc syntax, it is possible to select the Carrier hosting
       the Module to test with a character string containing 'board'
       followed by a site number (in decimal e.g. board1, board14, etc...).
       Using this syntax, "amcsite6@board3" will select MMC located
       on AMC Module plugged in AMC site #6 of Carrier Board in slot #3.
   shmctest [testseq]
       execute Shelf Manager test(s).

   shelftest [testseq]
       execute Shelf test(s).

   nettest [testseq]
       execute Network test(s).

   list [mode] [testseq]
       list all available test scripts.
       mode is a test filter among [test, carriertest, mmctest, shmctest, shelftest, nettest].
       If no mode is specified, list all tests according to given options.
       testseq is an optional test list that will act as a filter as well.
       Note that only -i, -I, -c and -C  options are meaningful for this command
       (see below for options).
   OPTIONS:
      -p, --port=PORT             connect to port PORT (Default is 623)
      -a, --authentication=METHOD use authentication METHOD (Default is 0)
                                  (0=None, 1=MD2, 2=MD5, 4=Straight)
      -u, --user=USER             use USER as login (Default is "")
      -w, --passwd=PASSWD         use PASSWD to login (Default is "")
      -b, --autodeact             set this flag to indicate that ShMC
                                  auto deactivates FRU in M5 (Default is not set)
      -v, --verbose               enable verbose mode
      -q, --quiet                 if set, no messages are displayed on stdout during
                                  the test session. However, logs are still available.
      -Q, --almostquiet           like --quiet except that only log directory is displayed on stdout.
                                  Note that if -Q is set, -q has no effect.
      -f, --restorefrus           if set, FRUs initial hotswap state is restored
                                  at the end of the test session.
      -o, --nopresence            Do not check MMC/IPMC/FRU presence before starting the tests.
      -k, --check=CHECK           check commands responses (Hexadecimal number representing 4 bits)
                                  (Bit 0: check PICMG defined commands exact response length)
                                  (Bit 1: check IPMI  defined commands exact response length)
                                  (Bit 2: check PICMG defined commands reserved bits and fields)
                                  (Bit 3: check IPMI  defined commands reserved bits and fields)
                                  (Default is 7: Bit 0,1,2 = 1 and Bit 3 = 0)
      -l, --log=DIR               test log files directory will be created
                                  in subdir DIR (Default is "atca_tester_logs")
                                  of the log files root path - see ATCA_TESTER_LOGS_PATH
                                  environment variable description below.
      -n, --runs=#RUNS            number of test runs to execute (Default is 1)
      -s, --stop=LEVEL            stop on error depending on LEVEL (Default is 0)
                                  (0=don't stop, 1=stop on error, 2=stop on error or warning,
                                   3=stop on error, warning or info)
      -r, --random                shuffle test sequence before each run
      -i, --interactive           if set, select only interactive tests
                                  (Mutually exclusive with -I).
      -I, --nointeractive         if set, select only non interactive tests
                                  (Mutually exclusive with -i).
      -c, --nologcolor            if set, strip colors from log file.
      -C, --nocolor               if set, strip colors from log file and from stdout.
          --version               print version and exit.
      -x, --xmlfile=FILE          use XML FILE for Description test.
      -h, --help                  print this page.
  TIMEOUT OPTION:
 -t, --timeout   Timeout in seconds for the responses to come from the DUT.
  MINISCOPE OPTION:
      -H, --minihost              IP address or Host name of your PC where miniscope is running.
      -P, --miniport    Port of your PC at which miniscope is running.
   ENVIRONMENT VARIABLES:
      ATCA_TESTER_LOGS_PATH
             Log files root path. If not defined, defaults to current working
             directory. Subdir defined by --log option described above will
             be appended to it.

Tuesday, September 25, 2012

Auto FTP transfer in shell script

Credit to Sim Wei Chieh

How to create shell script to auto ftp transfer

Objective:
- Create a new folder each time perform ftp transfer to target server with a set of files through wildcard.

Here is the code for autoftp.sh:

Time=$(date +"%F_%HH%MM%SS")
ftp -n <        open
        user
        binary
        prompt
        cd /home//
        mkdir timeoutput_top_error_log_$Time
        cd timeoutput_top_error_log_$Time
        lcd /root
        mput setoffilenames*
        bye
EOF