Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Sunday, July 31, 2011

Send automatic predefined input variable parameters to a script called by another script in bash through command line prompt

If you want to run a bash script inside a bash script to automate it, but the inside bash script asks and waits for a keyboard input variable from the user to proceed, this tip will become handy.

$ ./your_bash_script1.sh
Welcome to the XYZ script
Would you like to rewrite the output files? Please input Y for yes or N for no
Now script waits for Y or N input from user. i.e you have to input Y or N to proceed. So if you want to put these script inside another bash script, you would have to enter is as many times and it asks. How to automate a predefined input, say Y, to it and sit lazy while the script does everything by itself and finishes off?. Try echo piping

#!/bin/bash
#Send automatic predefined input variable parameter to a script called by another script
#in bash through command line prompt in Linux.linux bash through command prompt
echo "Y" | ./your_bash_script1.sh
echo "N" | ./your_bash_script2.sh

This will take 'Y' as the user input for 'your_bash_script1.sh' and N for your_bash_script2.sh

Thursday, January 27, 2011

How to change or modify the openSuse 11.3 KDE4 "My Computer" sysinfo window background color to match your desktop theme color

Sometimes you change your Desktop background image and change the theme to your favorite eye candy style. But "My Computer" stays the same old green color.

The images for the KDE4 sysinfo "My Computer" are stored at
/usr/share/kde4/apps/sysinfo/about/images


-rw-r--r-- 1 root root 2.5K 2008-06-19 11:01 sysinfo.png
-rw-r--r-- 1 root root 4.0K 2008-06-19 11:01 network.png
-rw-r--r-- 1 root root 4.1K 2008-06-19 11:01 mem.png
-rw-r--r-- 1 root root 3.1K 2008-06-19 11:01 launch.png
-rw-r--r-- 1 root root 5.8K 2008-06-19 11:01 inner-bcg.png
-rw-r--r-- 1 root root 2.9K 2008-06-19 11:01 hdds.png
-rw-r--r-- 1 root root  773 2008-06-19 11:01 hdd.png
-rw-r--r-- 1 root root 1.1K 2008-06-19 11:01 dirs.png
-rw-r--r-- 1 root root 2.7K 2008-06-19 11:01 cpu.png
-rw-r--r-- 1 root root 3.7K 2008-11-11 08:11 display.png
-rw-r--r-- 1 root root 591K 2010-07-05 19:05 background.png






1. Make a backup copy of the images, 'background.png' and 'inner-bcg.png'
2. Open them with Gimp > Colorize > Change to your favorite color
3. Replace the original
4. Now open My Computer from Desktop and you should see the new colors.


Right click on "My Computer" and 'open with' > kwrite... You must see a lot of information now on the XML page
/usr/share/kde4/apps/sysinfo/about/my-computer.html

This html page has more details to explore

Friday, January 14, 2011

Helpful commands for Linux cluster job management

qstat

qstat -a

qstat -an

qstat -f : to see full details of a job
gstat -a

finger
qdel

To kill all of your jobs: (queued and running)
for x in `qstat -a | grep 'username' | awk -F. {'print $1'}`;do qdel $x; done


To run a python program script command in a cluster node:


        ####################################################

        # /usr/bin/python   # XY run on linux cluster.
        # Run as $python XY-v1.0.py prg_script(.py)
        # Advantage of the scripts is that this can be used to run XY # in any node processor
        # of the cluster (or any linux cluster with PBS). But 1 job runs only on a single cpu

        import sys, posix, fileinput, string, re

        # XY path installed in your system
        path = "/XY/bin"
        stem = sys.argv[1]
        cwd = posix.getcwd()
        N = 0
        jobname = """%s""" % (stem)
        command = """echo "#PBS -l nodes=1

        #PBS -m ae
        #PBS -M your_e-mail
        #PBS -l walltime=3:00:00
        #PBS -l mem=512mb
        #PBS -S /bin/bash

        cd %s
        %s/bin/xy %s.py" > %s.j
        chmod +x %s.j
        qsub %s.j


        """ % (cwd, path, stem, jobname, jobname, jobname)
        posix.system(command)
         ####################################################

Friday, November 12, 2010

Sunday, October 17, 2010

Colorful BASH prompt: How to display BASH prompt with multiple colors

Add this line to the .bashrc

PS1='\[$(tput bold)$(tput setb 4)$(tput setaf 7)\]\u@\h:\w $ \[$(tput sgr0)\] '


More references:

http://wiki.archlinux.org/index.php/Color_Bash_Prompt
http://www.systhread.net/texts/200703bashish.php
http://www.thegeekstuff.com/2008/09/bash-shell-ps1-10-examples-to-make-your-linux-prompt-like-angelina-jolie/
http://www.cyberciti.biz/faq/bash-shell-change-the-color-of-my-shell-prompt-under-linux-or-unix/

Useful Vi editor commands

VI Navigation  [escape key = ]
0  [zero] = Move to beginning of line
G         = Go to end of file
5G        = Move to beginning of 5th line
u         = Undo
.         = Repeat last command
x         = Delete character
dd        = Delete line
dw        = Delete word
d$        = Delete from cursor to end of line
$ then J  = Join/append following line with current
$ then a  = Append input at end of line
A         = Append input at end of line [same as above, but one less key stroke]
i         = Insert text at cursor
/         = Bottom of screen type search string and  will move 
                 cursor to first occurrence

Replace text
 
.  :1,$s /and/AND/g
   ^^^^^   ^   ^  ^
   |||||   |   |  |
   |||||   |   |  \----------- Globally
   |||||   |   \-------------- Replace with
   |||||   \------------------ Find
   |||||
   ||||\---------------------- substitute for text
   |||\----------------------- To last line
   ||\------------------------ separator
   |\------------------------- From line "1"
   \-------------------------- ":" operator to start command processing
Useful tid bit to remove EOL characters from DOS file 
[use key sequence "" together for EOL char]
 :%s/^M$//


Write lines to new file
:1,10w abc     [puts lines 1~10 into file abc]
Change working file from current to file abc [be sure to save first]
:e abc
Read abc file into working file after cursor
:r abc


Execute command from prompt
:!cmd    [where cmd is could be a bash command]
Example ->    :r !date   [inserts time and date at prompt]
From online wiki resource: http://en.wikibooks.org/wiki/Linux_Guide/Using_the_shell

Useful Linux command compilation

Set system date/time

: date -s "17 OCT 2010 13:00:00"

: hwclock -systohc



Change the time stamps of files

: touch foo


File Permissions

chmod -R ugoa =+- rwx filename
       ^ ^^^^ ^^^ ^^^     ^
       | |||| ||| |||     |
       | |||| ||| |||     \---------- file or directory
       | |||| ||| |||                 --------------------
       | |||| ||| ||\---------------- Execute
       | |||| ||| |\----------------- Write
       | |||| ||| \------------------ Read
       | |||| |||                     --------------------
       | |||| ||\-------------------- Remove
       | |||| |\--------------------- Add
       | |||| \---------------------- assign
       | ||||                         --------------------
       | |||\------------------------ All
       | ||\------------------------- Others
       | |\-------------------------- Group
       | \--------------------------- User
       |                              --------------------
       \----------------------------- Recursively 
                                      --------------------
       Usage: chmod g+w filename
 
 
From : http://en.wikibooks.org/wiki/Linux_Guide/Using_the_shell 
An excellent resource of information with clear explanations